473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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
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
1 1436
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

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

Similar topics

8
by: Polar | last post by:
I am having troubles finding the parse error in this script. I've been checking for weeks. I am too new to the subject I guess. I am trying to show a readord and them have a form at the bottom...
1
by: Anand | last post by:
Hi i am having trouble adding a recordset into the access database, the code seems to be working fine it passs and parses through all variables just fine without showing any errors and also when i...
22
by: stoppal | last post by:
need to extract all text between the following strings, but not include the strings. "<!-- #BeginEditable "Title name" -->" "<p align="center">#### </p>" I am using preg_match(????, $s,...
1
by: MLH | last post by:
Am having trouble with the filter property setting below. Would like to filter the listing to car makes beginning with "D". I'm blowing it on the filter spec somehow??? Sub OpenRecordsetX() ...
3
by: Michael | last post by:
Hi all, I'm having trouble PInvoking a TCHAR within a struct. I'll paste the specific struct's API definition below. I've tried so many numerous variations. The main Win32 error I get is...
5
by: tkondal | last post by:
Hi all. I just started looking at Python's ctypes lib and I am having trouble using it for a function. For starters, here's my Python code: from ctypes import*; myStringDLL=...
18
by: fishwick | last post by:
I haven't really done any css in quite a while, and am banging my head against the wall trying get the rudimentary layout together of a church website home page to display correctly - I don't want...
2
by: Stu | last post by:
Hi guys, I've been having trouble getting the clock function to work portably, please could I get some thoughts? <Possibly OT comments> It works fine on my laptop (under WinXP) and on my...
8
by: cutlass | last post by:
Need you assistance to anyone who is willing to offer. I have been working on this script and can't get it to work. The issue I'm having is the statement: function validateSender($Address)...
1
by: Connor Bergman | last post by:
Im trying to create a bank statement basically, and Im having trouble formatting the output to a grid, from a .txt file. And I wrote the file, and can read the first line, and want to pull the date...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.