Jump to content

Help with a simple calculation?


johnnys

Recommended Posts

Hi Guys,

 

I'm just starting to work with Fabrik & Joomla, and need help with a some custom calculation.

 

Quick question regarding two drop down boxes I am creating a form for past pupils of a school.
 
First drop down box is called 'Year of Leaving' {member_app_year_out} and offers options from '1930' right through to '2014' (lots!).
 
Second drop down box is called 'Membership Type' {member_app_type} and offers two options 'Full Membership £20' and 'Reduced Membership £10'.
 
I want the second drop down box (Membership Type) to be dependant on the selection from the first drop down box. The rule is that 'If you have left the school within the past 7 years, you qualify for a Reduced Membership of £10'. So I want users to select e.g. 2008 and only see 'Reduced Membership', and users who select e.g. 2001 to only see 'Full Membership'. 
 
This also needs to update each year. 
 
How can I do this? Something like if {member_app_year_out} = '(now)' - 7 
 
Apologies for my lack of programming knowledge, I'm learning.
 
Thanks in advance,
 
J
Link to comment
https://forums.phpfreaks.com/topic/286115-help-with-a-simple-calculation/
Share on other sites

As Barand indicated, let your calculation take care of the fee.  Getting the year from their input you could use something like:

<?php
$years =  strtotime('-8 years');
$ref_date = date('Y', $years);
echo '<br />';
echo $ref_date.'<br/>';
$date_left = 2000; //example date from the form
echo $date_left. '<br />';
if($date_left > $ref_date){//if less than 8 years it must be 7 or less
$membership = 10;}// if less than 8
else $membership = 20;//if more than 7
echo $membership;
?>

Use the $membership as the fee.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.