Hello,
I am reading data from a table and I first create a summary page of all the query results, then the use can click on a result to see the detailed page (with all fields displayed). From that detailed page I want to have two possible navigation buttons: "back" - goes back to the summary
"next" - goes to the next detailed page from the summary list
When the user clicks the linked result, he will go to mysite.com/details.php?id=001&next=002 so the variables are passed in the url like that (this is an ssl secure intranet page).
My code looks like this
$result = mysql_query($query);
if (!$result)
{
echo "data read error.";
echo mysql_errno() . " : " . mysql_error();
exit;
}
$num_results = mysql_num_rows($result);
// print summary page
if ($num_results >0)
{
for ($i=0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
echo '<tr>';
// create link to detail page
// need to pass parameter 'next' for clicking to next page from details page, so get next booking ref and pass as parameter
if ($i < $num_results)
{
$next = mysql_result($result,$i+1,"bookingref");
echo '<td><a href="detail.php?id='.mysql_real_escape_string($row[bookingref]).'&next='.$next.'">'.$row[bookingref].'</a></td>';
}
else
echo '<td><a href="detail.php?id='.mysql_real_escape_string($row[bookingref]).'">'.$row[bookingref].'</a></td>';
echo '<td>Unconfirmed</td>';
...echo more fields
The above code doesn't work, when I loop through the array of results, the last row is always out of bounds. It seems like maybe the mysql_result() function is advancing the pointer.
What is the correct way to do this? The code works like this if I don't use the "next" parameter:
$result = mysql_query($query);
if (!$result)
{
echo "data read error.";
echo mysql_errno() . " : " . mysql_error();
exit;
}
$num_results = mysql_num_rows($result);
// print summary page
if ($num_results >0)
{
for ($i=0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
echo '<tr>';
// create link to detail page
// need to pass parameter 'next' for clicking to next page from details page, so get next booking ref and pass as parameter
echo '<td><a href="detail.php?id='.mysql_real_escape_string($row[bookingref]).'">'.$row[bookingref].'</a></td>';
echo '<td>Unconfirmed</td>';
...echo more fields