As u can see i have two input fields if, i enter in first field numbers between 1 and 22 result is 128.13,now i need discount on that result if i enter 1 in second field, result need to be 128.13 - 1.28,
i found solution for that and works fine with this code
but since I have a huge price list it is quite hard to type 99 if statemant for every price,basicly for every 1% i need to code elseif statement…i hope there is another way to do this or shorter way…Tnx for help.
Which is why I asked what is the logic behind how it’s calculated. From the discount code you wrote here and the “for every 1% I need to code elseif statement” it seems like this would be enough. But without more info it’s impossible to answer properly
this is price list, i have 5 more this lists with another prices but other categories,same values but other price… first cat is 128.13 second is 153.75 third is 179.38 and so on…
This not spelled correctly “for every 1% I need to code elseif statement” , correctly is i dont want to code for every 1 % , hope there is some calculation formula to do this automatically.tnx
The problem is only work first line of code, if i enter year 2011 or lower and ccm 1100 resutl is 15.00 thats ok ,but if i enter ccm over 1150 result is 15.00 again its not 20.00…Tnx
This is too complicated for an if or a switch statement. Without seeing your form it’s difficult to be sure, but it looks like you expect a user to choose a year and an area then provide a discount. I’d implement this as a lookup table. Something like:
// If you post your actual form, we can show you how to implement getArea() and getYear()
$area = getArea(); // $area will now be something like 1200 - a value from your top row
$year = getYear(); // $year will now be something like 2017 - a value from your left column
/**
* This is a truncated example - you'd put the rest of your table rows in here in a similar fashion
*/
$discounts = array(
// This key is from your left column
2018 => array(
// Add your row values from highest to lowest
// This key is the lowest number from your top row.
// The value is the cell form this row and column: the cell from row 2018 and column 3000 is 1000
3000 => 1000,
2500 => 650,
2000 => 200,
1600 => 75,
1300 => 50,
1150 => 40,
// Use 0 as the key for your leftmost column
0 => 30
)
// Add the rest of your rows here...
);
// Get the row you want to look at
$year_discounts = $discounts[$year];
foreach ($year_discounts as $minimum_area => $area_discount) {
/**
* Check your user's area against the minimum area for each discount.
* Once the user's area is greater than a discount's minimum area, apply that discount.
*/
if ($area >= $minimum_area) {
$discount = $area_discount;
break;
}
}
$discount should now be the discount you want to apply.
Thank u for help, im finish with discount everythings work fine,this is another problem,as u can see in table is year of the car and engine ccm, year is left side of table,upper is cm3,in the middle of table is tax,if i enter for example 2008 in year field and 1000 in ccm field result need to be 15.00…if year is 2008 and ccm between 1151 and 1300 result need to be 20.00 etc…
Ok. In future you’d be best to create new questions as new topics. This makes it easier for people to keep track. The lookup approach I gave above should work for what you describe.