Implementing a multi page PHP system for SQL Query
Posted: Tue Dec 01, 2009 6:09 pm
Hello all,
I am currently trying trying to re-write a piece of PHP code for multi page navigation. The code works very well but unfortunately it is no pulling over a thousand rows from the database and is subsequently returning over 100 pages, like this:

What I am looking to do is to make some sort of a limit so it will only display say pages 1 to 5 then the equivalent of a "more" IE: 1,2,3,4,5 ...
This is the code as it is at the moment; I have no idea where to start so any help anyone could provide would be very much appreciated.
The "back end" code:
The "Display" code
If you want to see the site as rendered PHP it is http://www.supernaturalufo.com
Thanks in advance,
Trinitrotoluene
I am currently trying trying to re-write a piece of PHP code for multi page navigation. The code works very well but unfortunately it is no pulling over a thousand rows from the database and is subsequently returning over 100 pages, like this:
What I am looking to do is to make some sort of a limit so it will only display say pages 1 to 5 then the equivalent of a "more" IE: 1,2,3,4,5 ...
This is the code as it is at the moment; I have no idea where to start so any help anyone could provide would be very much appreciated.
The "back end" code:
Code: Select all
// This is the logic for the page navigation
$pages = intval($numrows/$limit); // Number of results pages.
// $pages now contains int of pages, unless there is a remainder from division.
if ($numrows%$limit) {
$pages++;} // has remainder so add one page
$current = ($page/$limit) + 1; // Current page number.
if (($pages < 1) || ($pages == 0)) {
$total = 1;} // If $pages is less than one or equal to 0, total pages is 1.
else {
$total = $pages;} // Else total pages is $pages value.
$first = $page + 1; // The first result.
if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit;} //If not last results page, last result equals $page plus $limit.
else{
$last = $numrows;} // If last results page, last result equals total number of results.Code: Select all
// Display the amount of pages code
if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href=\"http://www.supernaturalufo.com/index.php?c=$categoryid&page=$back_page&limit=$limit\">back</a> \n");}
for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit*($i - 1);
if ($ppage == $page){
echo("<b>$i</b> \n");} // If current page don't give link, just text.
else{
echo("<a href=\"http://www.supernaturalufo.com/index.php?c=$categoryid&page=$ppage&limit=$limit\">$i</a> \n");}
}
if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo(" <a href=\"http://www.supernaturalufo.com/index.php?c=$categoryid&page=$next_page&limit=$limit\">next</a>\n");}
?>
<font color="#2c3644">| <?=$numrows?>Thanks in advance,
Trinitrotoluene