Hi,
I assume you mean adding next/previous links?
Okay, do this:
First declare a variable like $offset which will be retrieved from a GET name=value pair:
$offset = $_GET['offset'];
Next decide on the # of entries (rows) you want to display and enter that number + 1 in another variable:
// For 20 rows, use 21
$numrows = 21;
The reason you want 21 is because you will be retrieving 21 rows from the database yet only displaying 20 of them. If the 21st row exists in the database, then you know that you can display an additional page since there are more entries.
Construct your query like this:
$SQ = "SELECT * FROM products, company WHERE products.cid=$cid AND company.cid=$cid LIMIT $offset,$numrows";
// print the "Previous" link if offset is NOT 0
if ($offset != 0) {
print "<a href=\"script.php?offset=\" . ($offset - $numrows) . "\">Previous</a>\n";
}
// start a counter so you ONLY PRINT $numrows rows
$count = 1;
// now print your rows for this page
$result = @("SELECT * FROM products, company WHERE products.cid=$cid AND company.cid=$cid");
if (@$data = mysql_fetch_array($result))
{
do {
$title = $data["title"];
$thumbnail = $data["thumbnail"];
$id = $data["id"];
$info = $data["info"];
echo "<a href=\"$PHP_SELF?id=$id&cid=$cid\"><img src=\"$thumbnail\" hspace=\"5\" border=\"1\" alt=\"$title\"></a>";
$count++;
} while ( ($data = mysql_fetch_array($result)) && ($count < 21) );
}
else {
echo "</p>No items match your selection</p>.";
}
}
// finally, see if there is a 21st row. If there IS, then print the NEXT link
if (@$data = mysql_fetch_array($result)) {
print "<a href=\"script.php?offset=" . ($offset + $numrows) . "\">Next</a>";
}
that's it! I haven't tested the code, so there may be syntax errors. If anyone notices any flaws, please post!
-sridhar