problem with if statement help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ehpratah
    New Member
    • Mar 2012
    • 35

    problem with if statement help

    guys i'm having a really big problem right now..im trying to make a conditional statement using php but im having an logical error or syntax error..im trying to compute for the car rate but im not getting a correct output

    e.g

    i have a list of car which are "Small Car" "Innova" "Van" and there prices will depend on the location if the location is let say "Manila" or "Cam Sur" or "Boracay" then
    Small Car price is 550.00
    Innova price is 700.00
    Van price is 1000.00

    here is the code
    Code:
    <?php
     $vehicle;
      	$rhr;
    	$phr;
    	$total;
    	$totalhr;
    	$rday;
    	$pday;
    	$totald;
    	$totalday;
    	$rmonth;
    	$pmonth;
    	$totalm;
    	$totalmonth;
    
    
    if($origin=="NAIA 1" && $vehicle=="Small Car" && $destination=="Manila" || $destination=="Cam Sur" || $destination=="Boracay" )
    {
    	$perday=3000;
    	$permonth=9000;
    	$perhour=125;
    	$car=1740;
    
    if($rhr>$phr)
    		{
    		$total=($rhr)- ($phr);
    		$totalhr=$perhour * $total;
    	
    		}
    	else if($rhr==$phr)
    		{	
    		$totalhr;
    		}
    	if($rday>$pday)
    		{
    		$totald=($rday)-($pday);
    		$totalday=$perday * $totald;
    		}
    	else if($rday==$pday)
    		{
    		$totalday;
    		}
    		
    	if($rmonth>$pmonth)
    		{
    		$totalm=$rmonth-$pmonth;
    		$totalmonth=$totalm * $permonth;
    		
    		}
    	else if($rmonth==$pmonth)
    		{
    		$totalmonth;
    		}
    		$rate=$car+$totalhr+$totalday; 	
    }
    if($origin=="NAIA 1" && $vehicle=="Innova" && $destination=="Manila" || $destination=="Cam Sur" || $destination=="Boracay" )
    {
    	$perday=3000;
    	$permonth=9000;
    	$perhour=125;
    	$car=1740;
    
    if($rhr>$phr)
    		{
    		$total=($rhr)- ($phr);
    		$totalhr=$perhour * $total;
    	
    		}
    	else if($rhr==$phr)
    		{	
    		$totalhr;
    		}
    	if($rday>$pday)
    		{
    		$totald=($rday)-($pday);
    		$totalday=$perday * $totald;
    		}
    	else if($rday==$pday)
    		{
    		$totalday;
    		}
    		
    	if($rmonth>$pmonth)
    		{
    		$totalm=$rmonth-$pmonth;
    		$totalmonth=$totalm * $permonth;
    		
    		}
    	else if($rmonth==$pmonth)
    		{
    		$totalmonth;
    		}
    		$rate=$car+$totalhr+$totalday; 	
    }
    if($origin=="NAIA 1" && $vehicle=="Vans" && $destination=="Manila" || $destination=="Cam Sur" || $destination=="Boracay" )
    {
    	$perday=3000;
    	$permonth=9000;
    	$perhour=125;
    	$car=1740;
    
    if($rhr>$phr)
    		{
    		$total=($rhr)- ($phr);
    		$totalhr=$perhour * $total;
    	
    		}
    	else if($rhr==$phr)
    		{	
    		$totalhr;
    		}
    	if($rday>$pday)
    		{
    		$totald=($rday)-($pday);
    		$totalday=$perday * $totald;
    		}
    	else if($rday==$pday)
    		{
    		$totalday;
    		}
    		
    	if($rmonth>$pmonth)
    		{
    		$totalm=$rmonth-$pmonth;
    		$totalmonth=$totalm * $permonth;
    		
    		}
    	else if($rmonth==$pmonth)
    		{
    		$totalmonth;
    		}
    		$rate=$car+$totalhr+$totalday; 	
    }							?>

    in that code the "or" "||" condtion is not working please need help...
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    you should probabley change lines like this:
    Code:
    if($origin=="NAIA 1" && $vehicle=="Small Car" && $destination=="Manila" || $destination=="Cam Sur" || $destination=="Boracay" )
    to
    Code:
    if($origin=="NAIA 1" && $vehicle=="Small Car" && ( $destination=="Manila" || $destination=="Cam Sur" || $destination=="Boracay" ) )
    Because '&&' has higher precedence than '||'
    (see: docs )

    Comment

    • ehpratah
      New Member
      • Mar 2012
      • 35

      #3
      yeah thanks for the advice..i figured it out already but again thanks

      Comment

      Working...