By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,994 Members | 2,073 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,994 IT Pros & Developers. It's quick & easy.

trouble in nested if statement

P: 35
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
Expand|Select|Wrap|Line Numbers
  1. <?php    
  2. $zone;
  3. $vehicle;
  4. if($zone=="Manila" && $vehicle="Toyota VIOS 1.3 MT")
  5. {
  6.     $perday=3000;
  7.     $permonth=9000;
  8.     $perhour=125;
  9.     $car=1000;
  10.     $rhr;
  11.     $phr;
  12.     $total;
  13.     $totalhr;
  14.     $rday;
  15.     $pday;
  16.     $totald;
  17.     $totalday;
  18.     $rmonth;
  19.     $pmonth;
  20.     $totalm;
  21.     $totalmonth;
  22.     if($rhr>$phr)
  23.         {
  24.         $total=($rhr)- ($phr);
  25.         $totalhr=$perhour * $total;
  26.  
  27.         }
  28.     else if($rhr==$phr)
  29.  
  30.  
  31.     if($rday>$pday)
  32.         {
  33.         $totald=($rday)-($pday);
  34.         $totalday=$perday * $totald;
  35.         }
  36.     else if($rday==$pday)
  37.         {
  38.         $totalday;
  39.         }
  40.  
  41.     if($rmonth>$pmonth)
  42.         {
  43.         $totalm=$rmonth-$pmonth;
  44.         $totalmonth=$totalm * $permonth;
  45.  
  46.         }
  47.     else if($rmonth==$pmonth)
  48.         {
  49.         $totalmonth;
  50.         }
  51.         $rate=$car+$totalhr+$totalday;     
  52.  
  53. }
  54.  
  55.  
  56.  
  57. if($zone=="Manila" && $vehicle="Toyota VIOS 1.3 AT")
  58. {
  59.     $perday=3000;
  60.     $permonth=9000;
  61.     $perhour=125;
  62.     $car=3000;
  63.     $rhr;
  64.     $phr;
  65.     $total;
  66.     $totalhr;
  67.     $rday;
  68.     $pday;
  69.     $totald;
  70.     $totalday;
  71.     $rmonth;
  72.     $pmonth;
  73.     $totalm;
  74.     $totalmonth;
  75.     if($rhr>$phr)
  76.         {
  77.         $total=($rhr)- ($phr);
  78.         $totalhr=$perhour * $total;
  79.  
  80.         }
  81.     else if($rhr==$phr)
  82.         {    
  83.         $totalhr;
  84.         }
  85.     if($rday>$pday)
  86.         {
  87.         $totald=($rday)-($pday);
  88.         $totalday=$perday * $totald;
  89.         }
  90.     else if($rday==$pday)
  91.         {
  92.         $totalday;
  93.         }
  94.  
  95.     if($rmonth>$pmonth)
  96.         {
  97.         $totalm=$rmonth-$pmonth;
  98.         $totalmonth=$totalm * $permonth;
  99.  
  100.         }
  101.     else if($rmonth==$pmonth)
  102.         {
  103.         $totalmonth;
  104.         }
  105.         $rate=$car+$totalhr+$totalday;     
  106. }
  107. if($zone=="Manila" && $vehicle="Toyota VIOS 1.5 MT")
  108. {
  109.     $perday=3000;
  110.     $permonth=9000;
  111.     $perhour=125;
  112.     $car=3500;
  113.     $rhr;
  114.     $phr;
  115.     $total;
  116.     $totalhr;
  117.     $rday;
  118.     $pday;
  119.     $totald;
  120.     $totalday;
  121.     $rmonth;
  122.     $pmonth;
  123.     $totalm;
  124.     $totalmonth;
  125.     if($rhr>$phr)
  126.         {
  127.         $total=($rhr)- ($phr);
  128.         $totalhr=$perhour * $total;
  129.  
  130.         }
  131.     else if($rhr==$phr)
  132.         {    
  133.         $totalhr;
  134.         }
  135.     if($rday>$pday)
  136.         {
  137.         $totald=($rday)-($pday);
  138.         $totalday=$perday * $totald;
  139.         }
  140.     else if($rday==$pday)
  141.         {
  142.         $totalday;
  143.         }
  144.  
  145.     if($rmonth>$pmonth)
  146.         {
  147.         $totalm=$rmonth-$pmonth;
  148.         $totalmonth=$totalm * $permonth;
  149.  
  150.         }
  151.     else if($rmonth==$pmonth)
  152.         {
  153.         $totalmonth;
  154.         }
  155.         $rate=$car+$totalhr+$totalday;     
  156. }
  157. if($zone=="Manila" && $vehicle="Toyota VIOS 1.5 AT") 
  158. {
  159.     $perday=3600;
  160.     $permonth=9000;
  161.     $perhour=150;
  162.     $car=3500;
  163.     $rhr;
  164.     $phr;
  165.     $total;
  166.     $totalhr;
  167.     $rday;
  168.     $pday;
  169.     $totald;
  170.     $totalday;
  171.     $rmonth;
  172.     $pmonth;
  173.     $totalm;
  174.     $totalmonth;
  175.     if($rhr>$phr)
  176.         {
  177.         $total=($rhr)- ($phr);
  178.         $totalhr=$perhour * $total;
  179.  
  180.         }
  181.     else if($rhr==$phr)
  182.         {    
  183.         $totalhr;
  184.         }
  185.     if($rday>$pday)
  186.         {
  187.         $totald=($rday)-($pday);
  188.         $totalday=$perday * $totald;
  189.         }
  190.     else if($rday==$pday)
  191.         {
  192.         $totalday;
  193.         }
  194.  
  195.     if($rmonth>$pmonth)
  196.         {
  197.         $totalm=$rmonth-$pmonth;
  198.         $totalmonth=$totalm * $permonth;
  199.  
  200.         }
  201.     else if($rmonth==$pmonth)
  202.         {
  203.         $totalmonth;
  204.         }
  205.         $rate=$car+$totalhr+$totalday;     
  206. }
  207. if($zone=="Manila" && $vehicle="Toyota ALTIS 1.5 AT")
  208. {
  209.     $perday=3600;
  210.     $permonth=9000;
  211.     $perhour=150;
  212.     $car=3500;
  213.     $rhr;
  214.     $phr;
  215.     $total;
  216.     $totalhr;
  217.     $rday;
  218.     $pday;
  219.     $totald;
  220.     $totalday;
  221.     $rmonth;
  222.     $pmonth;
  223.     $totalm;
  224.     $totalmonth;
  225. if($rhr>$phr)
  226.         {
  227.         $total=($rhr)- ($phr);
  228.         $totalhr=$perhour * $total;
  229.  
  230.         }
  231.     else if($rhr==$phr)
  232.         {    
  233.         $totalhr;
  234.         }
  235. if($rday>$pday)
  236.         {
  237.         $totald=($rday)-($pday);
  238.         $totalday=$perday * $totald;
  239.         }
  240.     else if($rday==$pday)
  241.         {
  242.         $totalday;
  243.         }
  244.  
  245. if($rmonth>$pmonth)
  246.         {
  247.         $totalm=$rmonth-$pmonth;
  248.         $totalmonth=$totalm * $permonth;
  249.  
  250.         }
  251.     else if($rmonth==$pmonth)
  252.         {
  253.         $totalmonth;
  254.         }
  255.         $rate=$car+$totalhr+$totalday;     
  256. }
  257. if($zone=="Manila" && $vehicle="Toyota ALTIS 1.5 MT")
  258. {
  259.     $perday=3600;
  260.     $permonth=9000;
  261.     $perhour=150;
  262.     $car=3500;
  263.     $rhr;
  264.     $phr;
  265.     $total;
  266.     $totalhr;
  267.     $rday;
  268.     $pday;
  269.     $totald;
  270.     $totalday;
  271.     $rmonth;
  272.     $pmonth;
  273.     $totalm;
  274.     $totalmonth;
  275.  if($rhr>$phr)
  276.         {
  277.         $total=($rhr)- ($phr);
  278.         $totalhr=$perhour * $total;
  279.  
  280.         }
  281.     else if($rhr==$phr)
  282.         {    
  283.         $totalhr;
  284.         }
  285.     if($rday>$pday)
  286.         {
  287.         $totald=($rday)-($pday);
  288.         $totalday=$perday * $totald;
  289.         }
  290.     else if($rday==$pday)
  291.         {
  292.         $totalday;
  293.         }
  294.  
  295.     if($rmonth>$pmonth)
  296.         {
  297.         $totalm=$rmonth-$pmonth;
  298.         $totalmonth=$totalm * $permonth;
  299.  
  300.         }
  301.     else if($rmonth==$pmonth)
  302.         {
  303.         $totalmonth;
  304.         }
  305.         $rate=$car+$totalhr+$totalday;     
  306. }
  307. if($zone=="Manila" && $vehicle="Toyota Innova MT")
  308. {
  309.     $perday=4000;
  310.     $permonth=9000;
  311.     $perhour=167;
  312.     $car=4500;
  313.     $rhr;
  314.     $phr;
  315.     $total;
  316.     $totalhr;
  317.     $rday;
  318.     $pday;
  319.     $totald;
  320.     $totalday;
  321.     $rmonth;
  322.     $pmonth;
  323.     $totalm;
  324.     $totalmonth;
  325. if($rhr>$phr)
  326.         {
  327.         $total=($rhr)- ($phr);
  328.         $totalhr=$perhour * $total;
  329.  
  330.         }
  331.     else if($rhr==$phr)
  332.         {    
  333.         $totalhr;
  334.         }
  335.     if($rday>$pday)
  336.         {
  337.         $totald=($rday)-($pday);
  338.         $totalday=$perday * $totald;
  339.         }
  340.     else if($rday==$pday)
  341.         {
  342.         $totalday;
  343.         }
  344.  
  345.     if($rmonth>$pmonth)
  346.         {
  347.         $totalm=$rmonth-$pmonth;
  348.         $totalmonth=$totalm * $permonth;
  349.  
  350.         }
  351.     else if($rmonth==$pmonth)
  352.         {
  353.         $totalmonth;
  354.         }
  355.         $rate=$car+$totalhr+$totalday;     
  356. }
  357. if($zone=="Manila" && $vehicle="Toyota Grandia MT")
  358. {
  359.     $perday=4000;
  360.     $permonth=9000;
  361.     $perhour=167;
  362.     $car=4500;
  363.     $rhr;
  364.     $phr;
  365.     $total;
  366.     $totalhr;
  367.     $rday;
  368.     $pday;
  369.     $totald;
  370.     $totalday;
  371.     $rmonth;
  372.     $pmonth;
  373.     $totalm;
  374.     $totalmonth;
  375. if($rhr>$phr)
  376.         {
  377.         $total=($rhr)- ($phr);
  378.         $totalhr=$perhour * $total;
  379.  
  380.         }
  381.     else if($rhr==$phr)
  382.         {    
  383.         $totalhr;
  384.         }
  385.     if($rday>$pday)
  386.         {
  387.         $totald=($rday)-($pday);
  388.         $totalday=$perday * $totald;
  389.         }
  390.     else if($rday==$pday)
  391.         {
  392.         $totalday;
  393.         }
  394.  
  395.     if($rmonth>$pmonth)
  396.         {
  397.         $totalm=$rmonth-$pmonth;
  398.         $totalmonth=$totalm * $permonth;
  399.  
  400.         }
  401.     else if($rmonth==$pmonth)
  402.         {
  403.         $totalmonth;
  404.         }
  405.         $rate=$car+$totalhr+$totalday;     
  406. }
  407. if($zone=="Manila" && $vehicle="Toyota Camry AT")
  408. {
  409.     $perday=5200;
  410.     $permonth=9000;
  411.     $perhour=217;
  412.     $car=12000;
  413.     $rhr;
  414.     $phr;
  415.     $total;
  416.     $totalhr;
  417.     $rday;
  418.     $pday;
  419.     $totald;
  420.     $totalday;
  421.     $rmonth;
  422.     $pmonth;
  423.     $totalm;
  424.     $totalmonth;
  425. if($rhr>$phr)
  426.         {
  427.         $total=($rhr)- ($phr);
  428.         $totalhr=$perhour * $total;
  429.  
  430.         }
  431.     else if($rhr==$phr)
  432.         {    
  433.         $totalhr;
  434.         }
  435.     if($rday>$pday)
  436.         {
  437.         $totald=($rday)-($pday);
  438.         $totalday=$perday * $totald;
  439.         }
  440.     else if($rday==$pday)
  441.         {
  442.         $totalday;
  443.         }
  444.  
  445.     if($rmonth>$pmonth)
  446.         {
  447.         $totalm=$rmonth-$pmonth;
  448.         $totalmonth=$totalm * $permonth;
  449.  
  450.         }
  451.     else if($rmonth==$pmonth)
  452.         {
  453.         $totalmonth;
  454.         }
  455.         $rate=$car+$totalhr+$totalday;     
  456. }
  457.  if($zone=="Manila" && $vehicle="Toyota Grandia MT")
  458. {
  459.     $perday=4000;
  460.     $permonth=9000;
  461.     $perhour=167;
  462.     $car=4500;
  463.     $rhr;
  464.     $phr;
  465.     $total;
  466.     $totalhr;
  467.     $rday;
  468.     $pday;
  469.     $totald;
  470.     $totalday;
  471.     $rmonth;
  472.     $pmonth;
  473.     $totalm;
  474.     $totalmonth;
  475. if($rhr>$phr)
  476.         {
  477.         $total=($rhr)- ($phr);
  478.         $totalhr=$perhour * $total;
  479.  
  480.         }
  481.     else if($rhr==$phr)
  482.         {    
  483.         $totalhr;
  484.         }
  485.     if($rday>$pday)
  486.         {
  487.         $totald=($rday)-($pday);
  488.         $totalday=$perday * $totald;
  489.         }
  490.     else if($rday==$pday)
  491.         {
  492.         $totalday;
  493.         }
  494.  
  495.     if($rmonth>$pmonth)
  496.         {
  497.         $totalm=$rmonth-$pmonth;
  498.         $totalmonth=$totalm * $permonth;
  499.  
  500.         }
  501.     else if($rmonth==$pmonth)
  502.         {
  503.         $totalmonth;
  504.         }
  505.         $rate=$car+$totalhr+$totalday;     
  506. }
  507. if($zone=="Manila" && $vehicle="Nissan Urvan MT")
  508. {
  509.     $perday=4000;
  510.     $permonth=9000;
  511.     $perhour=167;
  512.     $car=4500;
  513.     $rhr;
  514.     $phr;
  515.     $total;
  516.     $totalhr;
  517.     $rday;
  518.     $pday;
  519.     $totald;
  520.     $totalday;
  521.     $rmonth;
  522.     $pmonth;
  523.     $totalm;
  524.     $totalmonth;
  525. if($rhr>$phr)
  526.         {
  527.         $total=($rhr)- ($phr);
  528.         $totalhr=$perhour * $total;
  529.  
  530.         }
  531.     else if($rhr==$phr)
  532.         {    
  533.         $totalhr;
  534.         }
  535.     if($rday>$pday)
  536.         {
  537.         $totald=($rday)-($pday);
  538.         $totalday=$perday * $totald;
  539.         }
  540.     else if($rday==$pday)
  541.         {
  542.         $totalday;
  543.         }
  544.  
  545.     if($rmonth>$pmonth)
  546.         {
  547.         $totalm=$rmonth-$pmonth;
  548.         $totalmonth=$totalm * $permonth;
  549.  
  550.         }
  551.     else if($rmonth==$pmonth)
  552.         {
  553.         $totalmonth;
  554.         }
  555.         $rate=$car+$totalhr+$totalday;     
  556. }
  557. if($zone=="Manila" && $vehicle="Nissan Cefiro AT" )
  558. {
  559.     $perday=5200;
  560.     $permonth=9000;
  561.     $perhour=217;
  562.     $car=12000;
  563.     $rhr;
  564.     $phr;
  565.     $total;
  566.     $totalhr;
  567.     $rday;
  568.     $pday;
  569.     $totald;
  570.     $totalday;
  571.     $rmonth;
  572.     $pmonth;
  573.     $totalm;
  574.     $totalmonth;
  575. if($rhr>$phr)
  576.         {
  577.         $total=($rhr)- ($phr);
  578.         $totalhr=$perhour * $total;
  579.  
  580.         }
  581.     else if($rhr==$phr)
  582.         {    
  583.         $totalhr;
  584.         }
  585.     if($rday>$pday)
  586.         {
  587.         $totald=($rday)-($pday);
  588.         $totalday=$perday * $totald;
  589.         }
  590.     else if($rday==$pday)
  591.         {
  592.         $totalday;
  593.         }
  594.  
  595.     if($rmonth>$pmonth)
  596.         {
  597.         $totalm=$rmonth-$pmonth;
  598.         $totalmonth=$totalm * $permonth;
  599.  
  600.         }
  601.     else if($rmonth==$pmonth)
  602.         {
  603.         $totalmonth;
  604.         }
  605.         $rate=$car+$totalhr+$totalday;     
  606. }
  607. if($zone=="Manila" &&$vehicle="Mercedez Benz AT")
  608. {
  609.     $perday=6400;
  610.     $permonth=9000;
  611.     $perhour=267;
  612.     $car=30000;
  613.     $rhr;
  614.     $phr;
  615.     $total;
  616.     $totalhr;
  617.     $rday;
  618.     $pday;
  619.     $totald;
  620.     $totalday;
  621.     $rmonth;
  622.     $pmonth;
  623.     $totalm;
  624.     $totalmonth;
  625. if($rhr>$phr)
  626.         {
  627.         $total=($rhr)- ($phr);
  628.         $totalhr=$perhour * $total;
  629.  
  630.         }
  631.     else if($rhr==$phr)
  632.         {    
  633.         $totalhr;
  634.         }
  635.     if($rday>$pday)
  636.         {
  637.         $totald=($rday)-($pday);
  638.         $totalday=$perday * $totald;
  639.         }
  640.     else if($rday==$pday)
  641.         {
  642.         $totalday;
  643.         }
  644.  
  645.     if($rmonth>$pmonth)
  646.         {
  647.         $totalm=$rmonth-$pmonth;
  648.         $totalmonth=$totalm * $permonth;
  649.  
  650.         }
  651.     else if($rmonth==$pmonth)
  652.         {
  653.         $totalmonth;
  654.         }
  655.         $rate=$car+$totalhr+$totalday;     
  656. }
  657. ?>
  658.  
  659. Rate:₱<?php echo number_format("$rate,2"); ?>    </p>
  660.  
  661.  
  662.  

i know it is a messy code but please help me guyz.
Apr 9 '12 #1
Share this Question
Share on Google+
1 Reply


P: 62
Well... if $zone is "Manila", it will always go into the last if statement, because $vehicle="Mercedez 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=="Mercedez 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.
Apr 9 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.