Mysql_fetch_assoc - Looping thru result sets
Moderator: General Moderators
-
markwenham
- Forum Newbie
- Posts: 13
- Joined: Fri Aug 16, 2002 11:33 pm
Mysql_fetch_assoc - Looping thru result sets
Can anyone tell me why this doesn't display two tables? The first table and
result set shows up, but the secong table does not appear. I have tried
resetting $allhotels but that gives me an error.
---Code----
<?
$allhotels_query = "select ID, hot_cod from hotelbkg order by hot_cod";
$allhotels = mysql_query($allhotels_query) or
die (mysql_error());
?>
<form method="post" action="<?$PHP_SELF?>">
<table border="1">
<?
while ($row = mysql_fetch_assoc($allhotels)){
?>
<tr>
<td><input name="bkg_ref" value="<?echo $row["hot_cod"]?>"></td>
<td><input name="ID" value="<?echo $row["ID"]?>"></td>
</tr>
<?}?>
</table>
<table border="1">
<?
reset($allhotels);
while ($row = mysql_fetch_assoc($allhotels)){
?>
<tr>
<td><input name="bkg_ref" value="<?echo $row["hot_cod"]?>"></td>
<td><input name="ID" value="<?echo $row["ID"]?>"></td>
</tr>
<?}?>
</table>
</form>
---Finish Code---
Thanks, Mark
result set shows up, but the secong table does not appear. I have tried
resetting $allhotels but that gives me an error.
---Code----
<?
$allhotels_query = "select ID, hot_cod from hotelbkg order by hot_cod";
$allhotels = mysql_query($allhotels_query) or
die (mysql_error());
?>
<form method="post" action="<?$PHP_SELF?>">
<table border="1">
<?
while ($row = mysql_fetch_assoc($allhotels)){
?>
<tr>
<td><input name="bkg_ref" value="<?echo $row["hot_cod"]?>"></td>
<td><input name="ID" value="<?echo $row["ID"]?>"></td>
</tr>
<?}?>
</table>
<table border="1">
<?
reset($allhotels);
while ($row = mysql_fetch_assoc($allhotels)){
?>
<tr>
<td><input name="bkg_ref" value="<?echo $row["hot_cod"]?>"></td>
<td><input name="ID" value="<?echo $row["ID"]?>"></td>
</tr>
<?}?>
</table>
</form>
---Finish Code---
Thanks, Mark
-
markwenham
- Forum Newbie
- Posts: 13
- Joined: Fri Aug 16, 2002 11:33 pm
Sorry forgot to use the code highlighter
Can anyone tell me why this doesn't display two tables? The first table and
result set shows up, but the second table does not appear. I have tried
resetting $allhotels but that gives me an error.
Thanks, Mark
Can anyone tell me why this doesn't display two tables? The first table and
result set shows up, but the second table does not appear. I have tried
resetting $allhotels but that gives me an error.
Code: Select all
<?
$allhotels_query = "select ID, hot_cod from hotelbkg order by hot_cod";
$allhotels = mysql_query($allhotels_query) or
die (mysql_error());
?>
<form method="post" action="<?$PHP_SELF?>">
<table border="1">
<?
while ($row = mysql_fetch_assoc($allhotels)){
?>
<tr>
<td><input name="bkg_ref" value="<?echo $rowї"hot_cod"]?>"></td>
<td><input name="ID" value="<?echo $rowї"ID"]?>"></td>
</tr>
<?}?>
</table>
<table border="1">
<?
reset($allhotels);
while ($row = mysql_fetch_assoc($allhotels)){
?>
<tr>
<td><input name="bkg_ref" value="<?echo $rowї"hot_cod"]?>"></td>
<td><input name="ID" value="<?echo $rowї"ID"]?>"></td>
</tr>
<?}?>
</table>
</form>No need to do this, just use the MySQL function equivalent to reset()volka wrote:$allhotes is not an array but a resource identifier.
If you want to get the data twice request it again from mysql or store every line in an extra array.
mysql_data_seek($allhotels,0);
This will put the internal pointer to the start of your result set.
-
markwenham
- Forum Newbie
- Posts: 13
- Joined: Fri Aug 16, 2002 11:33 pm
That will save a post
That little titbit will save me making an extra post.
Wait I just did?
Wait I just did?
how about using the highlighter for PHP?Sorry forgot to use the code highlighter
Code: Select all
<?php
//BlahBalh
echo hello;
?>