I got a great script for pagination.
include ("dbconnect.inc" );
$numresults=mysql_query("SELECT * FROM classmates WHERE year='$classof'" );
$numrows=mysql_num_rows($numresults)
or die ("query 1 failed" );
if (empty($offset)) {
$offset=0;
}
$limit=3; // change to number of items displayed per page
$query = "SELECT * FROM classmates WHERE year='$classof' limit $offset,$limit";
$result = mysql_query ($query)
or die ("query 2 failed" );
while($r=mysql_fetch_array($result))
{
/* change the names to the data in your tables */
$year=$r["year"];
$first=$r["first"];
$entry=$r["last"];
$maiden=$r["maiden"];
$classof=$classof;
/* display whatever you want (your data in the rows are now variables)! */
echo "$first<br>";
echo "$year" . "<br>";
}
if ($offset >= 3) {
$prevoffset = $offset - $limit;
print "<a href=""$PHP_SELF?offset=$prevoffset>PREV</a> ";
}
$pages=intval($numrows/$limit);
if ($pages < ($numrows/$limit)){
$pages=($pages + 1);
}
for ($i = 1; $i <= $pages; $i++) {
$newoffset = $limit*($i-1);
if ($newoffset == $offset) {
print "$i \n";
} else {
print "<a href=""$PHP_SELF?offset=$newoffset>$i</a> ";
}
}
//show next if not last
if (! ( ($offset/$limit) == ($pages - 1) ) && ($pages != 1) ) {
$newoffset = $offset+$limit;
print "<a href=""$PHP_SELF?offset=$newoffset>NEXT</a><p>";
}
as you can see from the queries I have set it to return values of those that graduated in a certain year from a search form select box.
The script will return the first page of $limit=3;
the problem is that when I click the next page I get an error - I suspect the error is because the WHERE statement is not answered. meaning $classof is not carried to the next page so I coded it into the offset like this . print "<a href=""$PHP_SELF?offset=$newoffset?classof=$classof>$i</a.>
That didnt work either
Any ideas how to carry the $classof over to the next page





Bookmarks