I have attempted a php if statement which should calculate values basis 2 paramteres:-
Price
Fuel - Petrol or Diesel or LPG or CNG
However - while executing the code - its only calculating the values when fuel type is not diesel
For instance when price is under 600000 and fuel is diesel - it still calculating .04 tax. Can you advise on whats wrong in the code. I have tried reworking - but could not get an answer
Below is Code
<?php
$a = $this->prodDet->v_price;
$b = $this->prodDet->v_fuel_type;
if(($a < 600000) && ($b != 'Diesel'))
{
$calculatedtax = (.04*$a);
echo($calculatedtax);
}
else if(($a < 600000) && ($b == 'Diesel'))
{
$calculatedtax = (.05*$a);
echo($calculatedtax);
}
else if((($a >= 600000) and ($a < 1000000)) and ($b != 'Diesel'))
{
$calculatedtax = (.07*$a);
echo($calculatedtax);
}
else if((($a >= 600000) and ($a < 1000000)) and ($b == 'Diesel'))
{
$calculatedtax = (.0875*$a);
echo($calculatedtax);
}
else if((($a >= 1000000)) and ($b != 'Diesel'))
{
$calculatedtax = (.10*$a);
echo($calculatedtax);
}
else if((($a >= 1000000)) and ($b == 'Diesel'))
{
$calculatedtax = (.125*$a);
echo($calculatedtax);
}
?>
Update I checked database value in some fields there's a blank space after Diesel For instance
Fuel Type = Diesel (There's a blank space after diesel word) Fuel Type = Petrol (There's a blank space after diesel word)
when removed this blank space Fuel Type = Diesel(No blank space after diesel word) Fuel Type = Petrol(No blank space after Petrol word)
the calculation happening correctly
Also php logic changed a bit
else if((($a >= 1000000)) and ($b == 'Petrol'))
{
$calculatedtax = (.10*$a);
echo($calculatedtax);
}
else if((($a >= 1000000)) and ($b == 'Diesel'))
{
$calculatedtax = (.125*$a);
echo($calculatedtax);
}
Can someone advise how to correct php if statement logic - so that calculation can be performed by ignoring that black space in Fuel type