Calculating age query

  • SjengAarts
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 20
  • Thank you received: 0

SjengAarts created the topic: Calculating age query

Hi,
I am trying to build a small update query to place the age in a db field (element = 1771). But I can't figure out how to find the value from calender element 1773 (dob)
and how to calculate the age with these 2 fields in a sql statement.
Can you help me?

$this->execPieceByName('ff_InitLib');
$db = JFactory::getDBO();
$now = Date("d-m-Y");

$sql="UPDATE #__facileforms_subrecords SET value ='$now' - element =1773 WHERE element = 1771";

$db->setQuery($sql);
$result = $db->execute();
#233020
  • Posts: 1965
  • Karma: 67
  • Thank you received: 238

mihaela replied the topic: Calculating age query

Hello,

Sorry for the late response, Crosstec Support staff was on collective holiday vacation, as noted in the forum.

Can you please explain what exactly data do you want to update in the table and with which value?
Do you want to update data after form submission with the date on which the form is submitted? If that is the case, which database rows should it affect on?

Regards,

Mihaela
#233218
  • SjengAarts
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 20
  • Thank you received: 0

SjengAarts replied the topic: Calculating age query

Hi Mihaela,
I want to update the field leeftijd (element 1782) in the database #__facileforms_subrecords each time before a user makes a viewlist with Contentbuilder (based on Breezingforms form Wachtlijst).
The calculation needs to be Today minus gebdatum (element 1773)

The view in contentbuilder always takes the stored value from the database. i want to show the real age (= today - gebdatum).
It is not nessecary to achieve this in the Contentbuilder view. I will make a refesh button or something.

At the moment i use this code:
$this->execPieceByName('ff_InitLib');
$db = JFactory::getDBO();
$now = Date("d-m-Y");

$sql="UPDATE #__facileforms_subrecords SET value =('$now' - element =1773) WHERE element = 1782";

$db->setQuery($sql);
$result = $db->execute();
#233260
  • Posts: 1965
  • Karma: 67
  • Thank you received: 238

mihaela replied the topic: Calculating age query

Hello,

If you by "each time before a user makes a viewlist with Contentbuilder" mean each time before the form is entered to be edited then it can be done. Is that what you want?
Where did you put this code:
$this->execPieceByName('ff_InitLib');
$db = JFactory::getDBO();
$now = Date("d-m-Y");

$sql="UPDATE #__facileforms_subrecords SET value =('$now' - element =1773) WHERE element = 1782";

$db->setQuery($sql);
$result = $db->execute();

Which date format are you using for gebdatum (element 1773)? Also, do you have a code that calculates the age in "leeftijd" field when is entering his birth date?

Regards,

Mihaela
#233297
  • SjengAarts
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 20
  • Thank you received: 0

SjengAarts replied the topic: Calculating age query

Yes Mihaela, now the code is in de before submit piece. Each record (from this form) must be updated. with the actual age if a new record is submitted.

The format of the field gebdatum is responsive calender (dd-mm-yyyy).

At the moment there is no code in de field leeftijd.
I want to show age as: #years, #months

Thanks in advance for your help.
#233321
  • Posts: 1965
  • Karma: 67
  • Thank you received: 238

mihaela replied the topic: Calculating age query

Hello again,

Now I understand what you want to achieve. You want that each time the form is entered in all records form that form age(leeftijd) is updated based on the the today's date and birth date (gebdatum) which was entered in the form.

What you want to achieve requires writing quite a bit of custom code which is out of scope of our support.
Either way, I will give you some guidelines how I would do that which I hope will help you achieve what you want.

First, you should write the query to "#_facileforms_records" table to get the all the id's from that table rows which have certain 'formname' in name column.

Next, you should loop through that id's retrieved form the query and for each id first write a query to #_facileforms_subrecords to get the birth date for that certain submission.
Next, you would have to write php code that calculates age from birth date and, last thing, you would have to write update query once again to #_facileforms_subrecords to update the leeftijd element's value for that certain record.

I hope that you will manage to make this work.

If you have more questions, feel free to ask.

Regards,

Mihaela
#233366
Moderators: ForumSupporttomeperica
Time to create page: 0.071 seconds

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99€

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here