Forum Moderators: coopster
index.php?id=1&move=-1 to go back one record
index.php?id=1&move=+1 to go forward one record
Example code:
<?php
mysql_connect("localhost", "username", "password");
mysql_select_db("database");
$query = "SELECT * FROM table WHERE id = $id " . $move;
$result = mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$record=mysql_result($result,$i,"name");
echo $name;
$i++;
}
?>
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in "" on line 15
<?php
include ("connection.php");
$query = "SELECT * FROM `ADDRESSES` WHERE ID = $ID " . $move;
$result = mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$record=mysql_result($result,$i,"FULLNAME");
echo $FULLNAME;
$i++;
}
echo "<a href=nextrecord.php?id=1&move=-1>Go Back</a>";
echo "<a href=nextrecord.php?id=1&move=+1>Next record</a>";
?>
<?php
mysql_connect("localhost", "username", "password");
mysql_select_db("database");
if(isset($_GET['id']) && (int)$_GET['id']) $id = $_GET['id'];
else $id = 1;$query = "SELECT * FROM table WHERE id = '$id' LIMIT 1";
$result = mysql_query($query);
if($num=mysql_numrows($result))
{
$record = mysql_fetch_assoc($result);
$name = $record["name"];echo $name;
}$next = $id + 1;
$prev = $id - 1;
?>
<a href="index.php?id=<? echo $prev;?>">Prev</a><br>
<a href="index.php?id=<? echo $next;?>">Next</a><br>
Hope this helps!
Michal Cibor
Kamakaze, you are using the register_globals on, never do that, because it is very risky and unsecure!
You are getting that error because in your Go Back and Next Record links you are refering to lowercase id and in your sql query you are refering to uppercase id.
mysql_numrows is working on the basis of your query and when you click your current links $ID is null and there are no results returned.
========================
I am aware of what I am doing. I was just giving him an example on how to accomplish what he is asking. How he takes that and applies it is up to him. Thanks for the comments though.