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.

else if (($from=='Cagayan De Oro' && $to=='Zamboanga' )||($from=='Zamboanga' && $to=='Cagayan De Oro')){
 $dest = 500;
$fare = $nonsp*$dest;
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>';
mysql_query("INSERT INTO `reservation` (
`res_id` ,
`from` ,
`to` ,
`day` ,
`date` ,
`nonsp` ,`amount`)
VALUES (
'$id', '$from', ' $to', '$txtshowDay', '$fromdate', '$nonsp','$fare'
)");
 echo "<form method='POST' action='temp.php'><center><table border='1' width='900' cellpadding='2' cellspacing='2'>
		<tr><td bgcolor='yellow'><font size='3'><b>Bus No.:</b></font></td>
		<td bgcolor='yellow'><font size='3'><b>Bus Type:</b></font></td>
		<td bgcolor='yellow'><font size='3'><b>Departure Time:</b></font></td>
		<td bgcolor='yellow'><font size='3'><b>Plate No.:</b></font></td>
		<td bgcolor='yellow'><font size='3'><b>Total Fare Amount:</b></font></td>
		<td bgcolor='yellow'><font size='3'><b>Bus Seats:</b></font></td>
		<td bgcolor='yellow'><font size='3'><b>Reserved: &nbsp;&nbsp;&nbsp;</b></font></td>
		<td bgcolor='yellow'><font size='3'><b>Available Seat:</b></font></td>
		<td bgcolor='yellow'><font size='3'><b>Select: &nbsp;&nbsp;&nbsp;</b></font></td></tr>";


$sql = mysql_query("SELECT * FROM cdozam")or die("error");

		while($row = mysql_fetch_array($sql))
		{
				$busno = $row['busno'];
				$bustype = $row['bustype'];
				$dep = $row['departure'];
				$plateno = $row['plateno'];
				$seat = $row['seat'];
				$res=$row['reserve'];
				$avail = $seat-$res;


		echo "<tr bgcolor='#EAEAEA'>
		<td><font size='3'>$busno</font></td>
		<td><font size='3'>$bustype</font></td>
		<td><font size='3'>$dep</font></td>
		<td><font size='3'>$plateno</td>
		<td><font color='red' size='3'><b>Php.  $fare.00</font></b></td>
		<td><font size='3'><center>$seat</center></font></td>
		<td><font size='3'><center>$res</center></font></td>
		<td><font size='3'><center>$avail</center></font></td>
		<input type='hidden' name='idres' value='$id'>
		<input type='hidden' name='iddum' value='$busno'>
		<input type='hidden' name='btype' value='$bustype'>
		<input type='hidden' name='plateno' value='$plateno'>
		<input type='hidden' name='dep' value='$dep'>
		<input type='hidden' name='fare' value='$fare'>
		<input type='hidden' name='seat' value='$seat'>
		<input type='hidden' name='avail' value='$avail'>
		<input type='hidden' name='res' value='$res'>
		<td>
		<input name='submit' type='image' src='Images/ReserveButton.jpg' height='30' width='80'/> </form></td>
		</tr>";
		}

		echo "</TABLE></center>";
	 }

try this.

$mytext = "";
$mytext .= "<tr bgcolor='#EAEAEA'>
		<td><font size='3'>$busno</font></td>
		<td><font size='3'>$bustype</font></td>
		<td><font size='3'>$dep</font></td>
		<td><font size='3'>$plateno</td>
		<td><font color='red' size='3'><b>Php.  $fare.00</font></b></td>
		<td><font size='3'><center>$seat</center></font></td>
		<td><font size='3'><center>$res</center></font></td>
		<td><font size='3'><center>$avail</center></font></td>
		<input type='hidden' name='idres' value='$id'>
		<input type='hidden' name='iddum' value='$busno'>
		<input type='hidden' name='btype' value='$bustype'>
		<input type='hidden' name='plateno' value='$plateno'>
		<input type='hidden' name='dep' value='$dep'>
		<input type='hidden' name='fare' value='$fare'>
		<input type='hidden' name='seat' value='$seat'>
		<input type='hidden' name='avail' value='$avail'>
		<input type='hidden' name='res' value='$res'>
		<td>
		<input name='submit' type='image' src='Images/ReserveButton.jpg' height='30' width='80'/> </form></td>
		</tr>";
		}

		$mytext .= "</TABLE></center>";
	 }

echo $mytext;

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

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...
:)

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

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,

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.

@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

<form method='POST' action='temp.php'>

and put it before

$mytext .= "<tr bgcolor='#EAEAEA'>

Hope that solves your problem.

hi if you want display all the rows fix below code

$sql = mysql_query("SELECT * FROM cdozam");
while($row = mysql_fetch_array($sql))

or
if you want display particular row you must specify condition.

$sql = mysql_query("SELECT * FROM cdozam where your condition");
while($row = mysql_fetch_array($sql))

fix this

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.