hi,
i'm using a pagination script i found here that shows "next" and "previous" links, but the client wants that changed to show all the pages returned as links (i.e. "1 2 3 4 5 6 7 last")
any suggestions on changing this script to represent that?
<?php
// clean up input
$pageid = substr($pageid, 0, 3); // or however big page max is
$pageid = EscapeShellCmd($pageid);
// build query - using 10 recs per page - but we read 11 rows to
// have a way of knowing if we are at end of file so we don't put
// out the 'next page' link
$skiprows = (($pageid - 1) 10); // number of rows to skip in query
$query = "SELECT FROM $table
LIMIT $skiprows, 11";
// connect to the database
if(!($dbh=mysql_connect ("localhost",
"$user",
"$pass")))
die("Cannot connect to the database");
// open the connected database
if (!mysql_select_db("$user",$dbh))
die("Cannot open the database");
// execute the query
if (!($result = @ mysql_query ($query, $dbh)))
die("Cannot execute query against the database");
// if we got some rows back then get some numbers and output page
$numrows = mysql_num_rows($result);
if ($numrows > 0)
{
for ($i = 1; $i <= 10; $i++)
{
// last page may have less than 10 rows
if ($row = @ mysql_fetch_array($result))
{
// do all the stuff to put out the row
} // if there are rows in array
} // for i
// now put out next and previous links
// if not on page 1, then do previous
if ($pageid > 1)
{
$oldpageid = $pageid - 1;
echo "<a href=\"pagescript.php?pageid=$oldpageid\">";
echo "Go Back to Page $oldpageid</a>";
}
// if rowcount less than 11, must be last page otherwise do link
if $(numrows > 10) // there will be a next page
{
$newpageid = $pageid + 1;
echo "<a href=\"pagescript.php?pageid=$newpageid\">";
echo "Go Forward to Page $newpageid</a>";
}
} // if $numrows > 0
?>