I am trying to display the results of a query onto multiple pages, with MySQL & PHP. So far, here is my code:
code:--------------------------------------------------------------------------------
// Page count
$stmt = mysql_query ("SELECT * FROM gallery");
$limit = 5;
$numrows=mysql_num_rows($stmt);
if (empty($page) || $page < 0)
{
$page = 0;
}
$NumOfPages = intval($numrows/$limit);
if ($numrows%$limit)
{
$NumOfPages++;
}
$case = mysql_query(
"SELECT * FROM gallery LIMIT $page,$limit");
if (!$case) {
echo("<P>Error performing query: " .
mysql_error() . "</P>"); exit();
}
// Display the text of each link in a paragraph
while ( $row = mysql_fetch_array($case) ) {
echo("<b>Case #" . $row["CaseID"] .
"</b><br><br><b>Name: </b>" . $row["Name"] .
"<br><b>Website: </b><a href='" . $row["Website"] . "'>" .
$row["Website"] . "</a><br><b>Email:</b> <a href='mailto:"
. $row["Email"] . "'>" . $row["Email"] . "</a><br><b>Instant
Messenger:</b> " . $row["IM"] . "<br><b>Comment:</b> "
. $row["Comm"] . "<br><br><center><img src='/gallery/" .
$row["Pic1"] . "'> <img src='/gallery/" .
$row["Pic2"] . "'></center><br><br><hr>");
}
for ($pagenumber=1; $pagenumber<=$NumOfPages; ++$pagenumber)
{
$page = $limit * ($pagenumber - 1);
echo ("<a
href='$php_self/gallery2.php?page=$pagenumber'>$pagenumber</a>
");
}
echo (" ");
And this is the page:
http://www.overclockersrip.com/gallery2.php
If you go there, and try to go to a different page, you will see my BIG problem. It should display 1-5 on on page, 6-10 on another, etc.
This code is from a guy on here, and others can get it to work, but I can't. I have tried to change damn near everything to get it to work. Can anone see my mistake in the code?
Thanks!