Jump to content

pagination


runnerjp

Recommended Posts

currently my pangination output looks like this

 

Page 1 of 1

      [1]

<?php
                                                                echo "<br>";

                                                                // Find out the total number of pages depending on the limit set
                                                                $numofpages = $rows / $page_rows;
                                                                $totalpages = ceil($numofpages);
                                                                // Start links for pages
                                                                $maxpage = $totalpages == 0 ? 1 : $totalpages; // add this line
                                                                echo "<p align=center>Page $pagenum of $maxpage <br /> "; // change this

                                                                // Sets link for previous 25 and return to page 1

                                                                if ($pagenum != 1)
                                                                {
                                                                                                $pageprev = ($pagenum - 1);
                                                                                                echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=forum&forum=$forum&pagenum=1\"><<</a>  ";
                                                                                                echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=forum&forum=$forum&pagenum=$pageprev\">PREV </a> ";
                                                                }
                                                                


                                                                // Loop thru all the pages and echo out the links
                                                                for ($i = 1; $i <= $numofpages; $i++)
                                                                {

                                                                                                if ($i == $pagenum)
                                                                                                {
                                                                                                                                echo "[" . $i . "] ";
                                                                                                }
                                                                                                else
                                                                                                {
                                                                                                                                echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=forum&forum=$forum&pagenum=$i\">$i</a> ";
                                                                                                }
                                                                }

                                                                // Check for straglers after the limit blocks
                                                                if (($rows % $page_rows) != 0)
                                                                {
                                                                                                if ($i == $pagenum)
                                                                                                {
                                                                                                                                echo "[" . $i . "] ";
                                                                                                }
                                                                                                else
                                                                                                {
                                                                                                                                echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=forum&forum=$forum&pagenum=$i\">$i</a> ";
                                                                                                }
                                                                }
                                                                // Print out the Next 25 and Goto Last page links
                                                                if (($rows - ($page_rows * $pagenum)) > 0)
                                                                {
                                                                                                $pagenext = $pagenum++;
                                                                                                echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=forum&forum=$forum&pagenum=$pagenext\">NEXT </a>  ";
                                                                                                echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=forum&forum=$forum&pagenum=$totalpages\">>></a>  ";
                                                                }                                                                                                                       
                                                                
?>/code]
how can i chanage the code so it outputs it like this

Pages: [1] 2 3 4 5 6  ... 2245

then from there on after if say page 2 is cliicked it adds the anouther 5 page links like so

Pages: 1 [2] 3 4 5 6 7  ... 2245
then
Pages: 1 2 [3] 4 5 6 7 8  ... 2245

Link to comment
https://forums.phpfreaks.com/topic/132006-pagination/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.