I have tried four different pagination scripts and I have the same problem with everyone of them. If I leave the select statement like this ...
"select * from table";
I have no problem with it. The links and everything works perfectly. If I change the select statement to have a "where" clause in it like this...
"select * from table where something ='$something'";
That is when I have a problem.
Let's suppose the query produces 100 results. I limit the results to 10 results per page. When my results are shown, I get a table with 10 results per page and 10 links at the bottom representing 10 results per page for 100 results, with the "next" and "previous" links too. The problem is when I click on one of the links. It seems that when I do this the variables are lost and I get zero results produced. Below is the exact script I am using for my site. This script is one that I actually got from this site in the tutorials. Can anyone please try THIS EXACT script and tell me if it works for them and if so what is it I may be doing wrong. I changed nothing in the script when I use it except the select statement. Thanks.
<?
$server = "";
$userid = "";
$pass = "";
$database = "";
$dbtable = "";
$limit = 20;
$con = mysql_connect("$server","$userid","$pass") or die ("Huh? What Server");
$db = mysql_select_db("$database",$con) or die("I said WHAT database");
if (empty($offset) || $offset < 0) {
$offset=0;
}
if (empty($index)) $index=0; / This is to count the line index of the results /
$getrows = mysql_query("select * from $dbtable WHERE category = 'Beanie Bears'", $con);
$numrows=mysql_num_rows($getrows);
$query = mysql_query("select * from $dbtable WHERE category = 'Beanie Bears' limit $offset,$limit", $con);
while ($result=mysql_fetch_array($query)){
$index++; /* Increment the line index by 1 */
// Your results layout goes here
}
if ($numrows <= $limit) {
/ Added this statement so if the result shows less that or the
equal ammount of the limit to show nothing at all , to kill
the "1" that was just generated /
}
else {
// Don't display PREV link if on first page
if ($offset!=0) {
$prevoffset=$offset-$limit;
echo "<a onMouseOver=\"window.status='Previous $limit Results'; return true\"; href=\"$PHP_SELF?offset=$prevoffset&index=$prevoffset\"><B>[Previous]</B></a>   ";
} /* I particularly like having the [Previous] on the first page
if it has enough results to display at all with my mod , just helps
set the over all structure of the navigation system its self
so ill just add this to the above if statement */
else echo "<b><font color=666666>[Previous]</font></b>   ";
/* If its not to your likeing simply comment it out ;) */
// Calculate total number of pages in result
$pages = intval($numrows/$limit);
// $pages now contains total number of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
// Now loop through the pages to create numbered links
// ex. 1 2 3 4 5 NEXT
for ($i=1;$i<=$pages;$i++) {
// Check if on current page
if (($offset/$limit) == ($i-1)) {
// $i is equal to current page, so don't display a link
echo " <b><font color=666666>$i</font></b> ";
} else {
// $i is NOT the current page, so display a link to page $i
$newoffset=$limit*($i-1);
echo " <a onMouseOver=\"window.status='Page $i Results'; return true\"; href=\"$PHP_SELF?offset=$newoffset&index=$newoffset\"><B>$i</B></a> \n";
}
}
// Check to see if current page is last page
if (!((($offset/$limit)+1)==$pages) && $pages!=1) {
// Not on the last page yet, so display a NEXT Link
$newoffset=$offset+$limit;
echo "    <a onMouseOver=\"window.status='Next $limit Results'; return true\"; href=\"$PHP_SELF?offset=$newoffset&index=$newoffset\"><B>[Next]</B></a><p>\n";
} /* Im doing the same thing here as i did in the [Previous] above */
else echo "   <b><font color=666666>[Next]</font></b>";
}
mysql_close($con);
?>