trouble in nested if statement

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

    trouble in nested if statement

    hi im having trouble in my codes..anybody please help me in my code i always get the last condition in my if statement..i always get the Mercedes Benz even i choose already another type of car here is the code
    Code:
    <?php	
    $zone;
    $vehicle;
    if($zone=="Manila" && $vehicle="Toyota VIOS 1.3 MT")
    {
    	$perday=3000;
    	$permonth=9000;
    	$perhour=125;
    	$car=1000;
    	$rhr;
    	$phr;
    	$total;
    	$totalhr;
    	$rday;
    	$pday;
    	$totald;
    	$totalday;
    	$rmonth;
    	$pmonth;
    	$totalm;
    	$totalmonth;
    	if($rhr>$phr)
    		{
    		$total=($rhr)- ($phr);
    		$totalhr=$perhour * $total;
    	
    		}
    	else if($rhr==$phr)
    		
    
    	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($zone=="Manila" && $vehicle="Toyota VIOS 1.3 AT")
    {
    	$perday=3000;
    	$permonth=9000;
    	$perhour=125;
    	$car=3000;
    	$rhr;
    	$phr;
    	$total;
    	$totalhr;
    	$rday;
    	$pday;
    	$totald;
    	$totalday;
    	$rmonth;
    	$pmonth;
    	$totalm;
    	$totalmonth;
    	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($zone=="Manila" && $vehicle="Toyota VIOS 1.5 MT")
    {
    	$perday=3000;
    	$permonth=9000;
    	$perhour=125;
    	$car=3500;
    	$rhr;
    	$phr;
    	$total;
    	$totalhr;
    	$rday;
    	$pday;
    	$totald;
    	$totalday;
    	$rmonth;
    	$pmonth;
    	$totalm;
    	$totalmonth;
    	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($zone=="Manila" && $vehicle="Toyota VIOS 1.5 AT") 
    {
    	$perday=3600;
    	$permonth=9000;
    	$perhour=150;
    	$car=3500;
    	$rhr;
    	$phr;
    	$total;
    	$totalhr;
    	$rday;
    	$pday;
    	$totald;
    	$totalday;
    	$rmonth;
    	$pmonth;
    	$totalm;
    	$totalmonth;
    	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($zone=="Manila" && $vehicle="Toyota ALTIS 1.5 AT")
    {
    	$perday=3600;
    	$permonth=9000;
    	$perhour=150;
    	$car=3500;
    	$rhr;
    	$phr;
    	$total;
    	$totalhr;
    	$rday;
    	$pday;
    	$totald;
    	$totalday;
    	$rmonth;
    	$pmonth;
    	$totalm;
    	$totalmonth;
    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($zone=="Manila" && $vehicle="Toyota ALTIS 1.5 MT")
    {
    	$perday=3600;
    	$permonth=9000;
    	$perhour=150;
    	$car=3500;
    	$rhr;
    	$phr;
    	$total;
    	$totalhr;
    	$rday;
    	$pday;
    	$totald;
    	$totalday;
    	$rmonth;
    	$pmonth;
    	$totalm;
    	$totalmonth;
     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($zone=="Manila" && $vehicle="Toyota Innova MT")
    {
    	$perday=4000;
    	$permonth=9000;
    	$perhour=167;
    	$car=4500;
    	$rhr;
    	$phr;
    	$total;
    	$totalhr;
    	$rday;
    	$pday;
    	$totald;
    	$totalday;
    	$rmonth;
    	$pmonth;
    	$totalm;
    	$totalmonth;
    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($zone=="Manila" && $vehicle="Toyota Grandia MT")
    {
    	$perday=4000;
    	$permonth=9000;
    	$perhour=167;
    	$car=4500;
    	$rhr;
    	$phr;
    	$total;
    	$totalhr;
    	$rday;
    	$pday;
    	$totald;
    	$totalday;
    	$rmonth;
    	$pmonth;
    	$totalm;
    	$totalmonth;
    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($zone=="Manila" && $vehicle="Toyota Camry AT")
    {
    	$perday=5200;
    	$permonth=9000;
    	$perhour=217;
    	$car=12000;
    	$rhr;
    	$phr;
    	$total;
    	$totalhr;
    	$rday;
    	$pday;
    	$totald;
    	$totalday;
    	$rmonth;
    	$pmonth;
    	$totalm;
    	$totalmonth;
    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($zone=="Manila" && $vehicle="Toyota Grandia MT")
    {
    	$perday=4000;
    	$permonth=9000;
    	$perhour=167;
    	$car=4500;
    	$rhr;
    	$phr;
    	$total;
    	$totalhr;
    	$rday;
    	$pday;
    	$totald;
    	$totalday;
    	$rmonth;
    	$pmonth;
    	$totalm;
    	$totalmonth;
    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($zone=="Manila" && $vehicle="Nissan Urvan MT")
    {
    	$perday=4000;
    	$permonth=9000;
    	$perhour=167;
    	$car=4500;
    	$rhr;
    	$phr;
    	$total;
    	$totalhr;
    	$rday;
    	$pday;
    	$totald;
    	$totalday;
    	$rmonth;
    	$pmonth;
    	$totalm;
    	$totalmonth;
    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($zone=="Manila" && $vehicle="Nissan Cefiro AT" )
    {
    	$perday=5200;
    	$permonth=9000;
    	$perhour=217;
    	$car=12000;
    	$rhr;
    	$phr;
    	$total;
    	$totalhr;
    	$rday;
    	$pday;
    	$totald;
    	$totalday;
    	$rmonth;
    	$pmonth;
    	$totalm;
    	$totalmonth;
    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($zone=="Manila" &&$vehicle="Mercedez Benz AT")
    {
    	$perday=6400;
    	$permonth=9000;
    	$perhour=267;
    	$car=30000;
    	$rhr;
    	$phr;
    	$total;
    	$totalhr;
    	$rday;
    	$pday;
    	$totald;
    	$totalday;
    	$rmonth;
    	$pmonth;
    	$totalm;
    	$totalmonth;
    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; 	
    }
    ?>
    
    Rate:₱<?php echo number_format("$rate,2"); ?>	</p>

    i know it is a messy code but please help me guyz.
  • limweizhong
    New Member
    • Dec 2006
    • 62

    #2
    Well... if $zone is "Manila", it will always go into the last if statement, because $vehicle="Merce dez Benz AT" is an assignment statement that assigns $vehicle to "Mercedez Benz AT" and evaluates to "Mercedez Benz AT", which converts to true. Actually all your if statements would be executed when $zone is equal to "Manila". I think you mean $vehicle=="Merc edez Benz AT".

    But really, you should re-think what you are doing. I don't know that much about PHP, but your "$variable; " lines do not seem to be accomplishing much. Moreover, if you want to do that for all models, you must consider using an associative array or a database look-up instead.

    Comment

    Working...