• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Need help to return simple age classifications

margarizaldi

New Member
Hi guys, I need your little help in making some age classifications based on birthday element input. To be honest, I'm not a programmer, so I'm confused to write the codes.
I have a birthday field using d.o.b element (`table___dob`), just under this element I have a calc element (`table___age_category`) which is needed to run a simple operation as follows:
- When the user's birthday is between 1 december 2000 and 30 nov 2004 this element should return 'Category A'
- When the birthday is between 1 dec 1977 and 30 nov 2000, it returns 'Category B'
- When the birthday is between 1 dec 1967 and 30 nov 1977, it returns 'Category C'
- Else is 'Not available'

I have tried to use:
PHP:
if ('{table___dob}' >= '2000-12-01' and '{table___dob}' <= '2004-11-30') {return 'Category A';}
...
...
else
{return 'Not Available';}
With ajax calculation = yes
and ajax observe fields is {table___dob}

The result is not reliable, sometimes it's correct and sometimes is not. I think I know that the only problem is on my knowledge in php.

Regards.
 
Last edited:
try with table___dob_raw

Gesendet von meinem GT-I9300 mit Tapatalk

Thanks for your suggestion, when I use _raw, the calc returned nothing. I found that the _raw uses '20,1,2000' format instead of '2000-1-20', and it didn't work with my calculation.

I've modified my code as follow:

PHP:
$dob = '{table___dob}';
if ($dob > '2004-11-30') {
  return '0';
  }
elseif ($dob > '2000-11-30') {
  return '1';
  }
elseif ($dob > '1977-11-30') {
  return '2';
  }
elseif ($dob > '1967-11-30') {
  return '3';
  }
else return 'None';

However, the results are weird:
  • In December 2004 and latter it is "0" (correct)
  • In February until september 2004 it is "1" (correct), but in January and October = "0" (incorrect)
  • In 2001 until 2003 it works fine
  • In 2000 the problem is even more crazy, it works in some dates and doesn't for some as I tried 4-9 Nov 2004 still show "1" instead of "2" while 10 and latter in November shows 2.
I don't know how many more this occured, but one thing to be sure is: It's bad and not reliable.

Ps: I'm still working in localhost using xampp for windows - PHP 5.6.28
 
Try to debug
var_dump($dob);exit;

With var_dump($dob);exit; I got blank page with text:
string(0) ""

Without exit; I got string(9) "2000-2-13" (screenshot attached)

Edit:

The above output is the result of
Code:
$dob = '{table___dob}';
var_dump($dob);exit;

I removed my php lines cause I didn't find any problem displayed when I just add var_dump($dob);exit; at the end of my lines.
 

Attachments

  • cats.jpg
    cats.jpg
    7.8 KB · Views: 24
Last edited:
It looks like the birthday element uses single digits for day and month, so (say) 2007-2-27 instead of 2007-02-27. Which will mess up any attempt at simple string comparisons. So you'll need to convert them into DateTime objects and test those. I'm on my phone at the moment, so can't write code, but if you search Google for something like "php DateTime compare dates" you should find plenty of Stack Overflow examples.

Sent from my HTC6545LVW using Tapatalk
 
It looks like the birthday element uses single digits for day and month, so (say) 2007-2-27 instead of 2007-02-27. Which will mess up any attempt at simple string comparisons. So you'll need to convert them into DateTime objects and test those. I'm on my phone at the moment, so can't write code, but if you search Google for something like "php DateTime compare dates" you should find plenty of Stack Overflow examples.

Sent from my HTC6545LVW using Tapatalk

Got it! After some googlings and experiments, I got it solved my problem. I use this:
PHP:
$source = new DateTime('{table___dob}');
$dob = $source->format('Y-m-d');
...

Thanks much cheesegrifts and troester for your helps and suggestions.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top