Pagination help for existing script
Posted: Mon Aug 30, 2010 1:03 pm
Hello All!
I have the following code that produces links from a database. Certain sets of results have over 3000 links. I can currently set the amount of links to display per page but that's it.
I would like to be able to truncate the 100+ page links to a few using pagination.
Any help would be greatly appreciated!
Here is the code:
Thanks in advance for any help....
I have the following code that produces links from a database. Certain sets of results have over 3000 links. I can currently set the amount of links to display per page but that's it.
I would like to be able to truncate the 100+ page links to a few using pagination.
Any help would be greatly appreciated!
Here is the code:
Code: Select all
<?php
echo "Results<br><HR WIDTH=100% SIZE=1><br>";
mysql_connect("mysite.com", "mysite_mysite", "mysitepassword") or die(mysql_error());
mysql_select_db("user_database") or die(mysql_error());
if (isset($_GET['pagenum']))
{
$pagenum = $_GET['pagenum'];
} else
{
$pagenum = 1;
}
$rpg = $pagenum;
$data = mysql_query("SELECT * FROM mydb WHERE mfg='golf'") or die(mysql_error());
$rows = mysql_num_rows($data);
$page_rows = 80;
$last = ceil($rows/$page_rows);
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$data_p = mysql_query("SELECT * FROM mydb WHERE mfg='golf' $max") or die(mysql_error());
while($info = mysql_fetch_array( $data_p ))
{
$page=$info['link'];
echo "<a href='$page' class='blue1'>". $info['title'] . "</a><br>";
}
echo "<p>";
if ($pagenum > $last)
{$pagenum=1;}
else
{
echo "<HR WIDTH=100% SIZE=1><br>";
$pagenum = 1;
while ($pagenum <= $last)
{
$next = $pagenum;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next' class='g5'>$pagenum</a> ";
$pagenum = $pagenum+1;
}
Echo "<br><br>Page $rpg of $last <br>";
}
?>