943,097 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 419
  • PHP RSS
Feb 9th, 2010
0

plz guyz help me with my while loop

Expand Post »
hi guys! can anyone help me about this problem. i want to select the desire data from a row but only the last row the will be posted not the data that i want to get. plz help me. its inside i a while loop.

PHP Syntax (Toggle Plain Text)
  1. else if (($from=='Cagayan De Oro' && $to=='Zamboanga' )||($from=='Zamboanga' && $to=='Cagayan De Oro')){
  2. $dest = 500;
  3. $fare = $nonsp*$dest;
  4. print '<div id="sulod" align="center"><font color="maroon">The total fare is &nbsp;&nbsp; Php.&nbsp;<font color="red">'.$fare.'.00 </font>&nbsp;&nbsp;for &nbsp;&nbsp;'.$nonsp.'&nbsp;&nbsp;&nbsp;passenger/s.&nbsp; Please Choose Bus Below...</font></div>';
  5. mysql_query("INSERT INTO `reservation` (
  6. `res_id` ,
  7. `from` ,
  8. `to` ,
  9. `day` ,
  10. `date` ,
  11. `nonsp` ,`amount`)
  12. VALUES (
  13. '$id', '$from', ' $to', '$txtshowDay', '$fromdate', '$nonsp','$fare'
  14. )");
  15. echo "<form method='POST' action='temp.php'><center><table border='1' width='900' cellpadding='2' cellspacing='2'>
  16. <tr><td bgcolor='yellow'><font size='3'><b>Bus No.:</b></font></td>
  17. <td bgcolor='yellow'><font size='3'><b>Bus Type:</b></font></td>
  18. <td bgcolor='yellow'><font size='3'><b>Departure Time:</b></font></td>
  19. <td bgcolor='yellow'><font size='3'><b>Plate No.:</b></font></td>
  20. <td bgcolor='yellow'><font size='3'><b>Total Fare Amount:</b></font></td>
  21. <td bgcolor='yellow'><font size='3'><b>Bus Seats:</b></font></td>
  22. <td bgcolor='yellow'><font size='3'><b>Reserved: &nbsp;&nbsp;&nbsp;</b></font></td>
  23. <td bgcolor='yellow'><font size='3'><b>Available Seat:</b></font></td>
  24. <td bgcolor='yellow'><font size='3'><b>Select: &nbsp;&nbsp;&nbsp;</b></font></td></tr>";
  25.  
  26.  
  27. $sql = mysql_query("SELECT * FROM cdozam")or die("error");
  28.  
  29. while($row = mysql_fetch_array($sql))
  30. {
  31. $busno = $row['busno'];
  32. $bustype = $row['bustype'];
  33. $dep = $row['departure'];
  34. $plateno = $row['plateno'];
  35. $seat = $row['seat'];
  36. $res=$row['reserve'];
  37. $avail = $seat-$res;
  38.  
  39.  
  40. echo "<tr bgcolor='#EAEAEA'>
  41. <td><font size='3'>$busno</font></td>
  42. <td><font size='3'>$bustype</font></td>
  43. <td><font size='3'>$dep</font></td>
  44. <td><font size='3'>$plateno</td>
  45. <td><font color='red' size='3'><b>Php. $fare.00</font></b></td>
  46. <td><font size='3'><center>$seat</center></font></td>
  47. <td><font size='3'><center>$res</center></font></td>
  48. <td><font size='3'><center>$avail</center></font></td>
  49. <input type='hidden' name='idres' value='$id'>
  50. <input type='hidden' name='iddum' value='$busno'>
  51. <input type='hidden' name='btype' value='$bustype'>
  52. <input type='hidden' name='plateno' value='$plateno'>
  53. <input type='hidden' name='dep' value='$dep'>
  54. <input type='hidden' name='fare' value='$fare'>
  55. <input type='hidden' name='seat' value='$seat'>
  56. <input type='hidden' name='avail' value='$avail'>
  57. <input type='hidden' name='res' value='$res'>
  58. <td>
  59. <input name='submit' type='image' src='Images/ReserveButton.jpg' height='30' width='80'/> </form></td>
  60. </tr>";
  61. }
  62.  
  63. echo "</TABLE></center>";
  64. }
Last edited by Ezzaral; Feb 9th, 2010 at 12:41 pm. Reason: Added code tags. Please use them to format any code that you post.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
joloms38 is offline Offline
3 posts
since Oct 2009
Feb 9th, 2010
0
Re: plz guyz help me with my while loop
try this.
PHP Syntax (Toggle Plain Text)
  1. $mytext = "";
  2. $mytext .= "<tr bgcolor='#EAEAEA'>
  3. <td><font size='3'>$busno</font></td>
  4. <td><font size='3'>$bustype</font></td>
  5. <td><font size='3'>$dep</font></td>
  6. <td><font size='3'>$plateno</td>
  7. <td><font color='red' size='3'><b>Php. $fare.00</font></b></td>
  8. <td><font size='3'><center>$seat</center></font></td>
  9. <td><font size='3'><center>$res</center></font></td>
  10. <td><font size='3'><center>$avail</center></font></td>
  11. <input type='hidden' name='idres' value='$id'>
  12. <input type='hidden' name='iddum' value='$busno'>
  13. <input type='hidden' name='btype' value='$bustype'>
  14. <input type='hidden' name='plateno' value='$plateno'>
  15. <input type='hidden' name='dep' value='$dep'>
  16. <input type='hidden' name='fare' value='$fare'>
  17. <input type='hidden' name='seat' value='$seat'>
  18. <input type='hidden' name='avail' value='$avail'>
  19. <input type='hidden' name='res' value='$res'>
  20. <td>
  21. <input name='submit' type='image' src='Images/ReserveButton.jpg' height='30' width='80'/> </form></td>
  22. </tr>";
  23. }
  24.  
  25. $mytext .= "</TABLE></center>";
  26. }
  27.  
  28. echo $mytext;
Last edited by nav33n; Feb 10th, 2010 at 2:55 am. Reason: For easy readability, wrap your code in [code][/code] tags.
Reputation Points: 12
Solved Threads: 32
Posting Whiz in Training
phpbeginners is offline Offline
226 posts
since Jul 2009
Feb 10th, 2010
0
Re: plz guyz help me with my while loop
what are you doing at line no. 29...?

I think you are giving the value to $row by ($row = mysql_fetch_array($sql)).
Well i have not read your program fully, so i can't understand your logic. But you but, use a condition when using while or for loop. by your condition i think your program can be gone in the infinite loop. and if it is going then please correct your line no 29. to
PHP Syntax (Toggle Plain Text)
  1. while($row == mysql_fetch_array($sql))

I am telling again... I am sorry but I doesn't read your program because I am in some hurry...

Have a nice day...
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
harshbavaliya is offline Offline
65 posts
since Jan 2010
Feb 10th, 2010
0
Re: plz guyz help me with my while loop
what are you doing at line no. 29...?

I think you are giving the value to $row by ($row = mysql_fetch_array($sql)).
Well i have not read your program fully, so i can't understand your logic. But you but, use a condition when using while or for loop. by your condition i think your program can be gone in the infinite loop. and if it is going then please correct your line no 29. to
PHP Syntax (Toggle Plain Text)
  1. while($row == mysql_fetch_array($sql))

I am telling again... I am sorry but I doesn't read your program because I am in some hurry...

Have a nice day...
Actually,
PHP Syntax (Toggle Plain Text)
  1. while($row == mysql_fetch_array($sql))
this will not make it work. This will check if $row is equal to the whatever returned by mysql_fetch_array($sql). So, it will not work.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Feb 10th, 2010
0
Re: plz guyz help me with my while loop
@OP, You should have <form> tag inside the while loop. What is happening in your case is, Only the last record's data is being set in the hidden field.

In short, Just take
PHP Syntax (Toggle Plain Text)
  1. <form method='POST' action='temp.php'>
and put it before
PHP Syntax (Toggle Plain Text)
  1. $mytext .= "<tr bgcolor='#EAEAEA'>
  2.  
Hope that solves your problem.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Feb 10th, 2010
0
Re: plz guyz help me with my while loop
hi if you want display all the rows fix below code
PHP Syntax (Toggle Plain Text)
  1. $sql = mysql_query("SELECT * FROM cdozam");
  2. while($row = mysql_fetch_array($sql))
or
if you want display particular row you must specify condition.
PHP Syntax (Toggle Plain Text)
  1. $sql = mysql_query("SELECT * FROM cdozam where your condition");
  2. while($row = mysql_fetch_array($sql))
fix this
Reputation Points: 12
Solved Threads: 27
Junior Poster
rajabhaskar525 is offline Offline
179 posts
since Nov 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Log Out Displayed
Next Thread in PHP Forum Timeline: how can use javascript alert dialog box into php





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC