socalnate Posted May 20, 2007 Share Posted May 20, 2007 Anybody know how to modify the code below so that I can limit the number of pages displayed per page? The current system display ALL the pages on ONE page. I would like to set a limit to 10 pages like this: Page 1 of 2000 FIRST PREV page1, page2, page3, page4, page5, page6, page7, page8, page9, page10 NEXT LAST :-\ ??? Nathan I would like to modify my current pagation system because it works well ###pager.php#### <?php class pager { function getPagerData($numHits, $limit, $page) { $numHits = (int) $numHits; $limit = max((int) $limit, 1); $page = (int) $page; $numPages = ceil($numHits / $limit); $page = max($page, 1); $page = min($page, $numPages); $offset = ($page - 1) * $limit; $ret = new stdClass; $ret->offset = $offset; $ret->limit = $limit; $ret->numPages = $numPages; $ret->page = $page; return $ret; } } ?> ###page.php### <?php require('pager.php'); // load pager // get the pager input values $page = $_GET['page']; $limit = 10; $result = mysql_query("SELECT count(*) FROM table"); $total = mysql_result($result, 0, 0); // work out the pager values $pager = Pager::getPagerData($total, $limit, $page); $offset = $pager->offset; $limit = $pager->limit; $page = $pager->page; // use pager values to fetch data $sql = "SELECT * FROM table ORDER BY sort_date DESC LIMIT $offset, $limit"; $res = mysql_query($sql); if(mysql_num_rows($res)) { while($row = mysql_fetch_array($res)) { ?> <!--TABLE LOOP START--> <tr> <td><?php echo $row[0];?></td> <td><?php echo $row[1];?></td> <td><?php echo $row[2];?></td> <td><?php echo $row[3];?></td> <td><?php echo $row[4];?></td> <td><?php echo $row[5];?></td> <td><?php echo $row[6];?></td> <td><?php echo $row[7];?></td> <td><?php echo $row[8];?></td> </tr> <!--TABLE LOOP END--> <?php } } else { echo "No sites entered into the database..."; } ?> </table> <?php // use $result here to output page content // output paging system (could also do it before we output the page content) echo "<div id=\"pagation\">"; if ($page == 1) // this is the first page - there is no previous page echo "Previous"; else // not the first page, link to the previous page echo "<a href=\"page2.php?page=" . ($page - 1) . "\">Previous</a>"; for ($i = 1; $i <= $pager->numPages; $i++) { echo " | "; if ($i == $pager->page) echo "Page $i"; else echo "<a href=\"page2.php?page=$i\">Page $i</a>"; } if ($page == $pager->numPages) // this is the last page - there is no next page echo " | Next"; else // not the last page, link to the next page echo " | <a href=\"page2.php?page=" . ($page + 1) . "\">Next</a>"; echo "</div>"; ?> </body> Link to comment https://forums.phpfreaks.com/topic/52202-code-help-limiting-number-of-pages-listed-on-pagation/ Share on other sites More sharing options...
PC Nerd Posted May 20, 2007 Share Posted May 20, 2007 um, i havent read the code.... but if your code lists eg pgs like: < 1 2 3 4 5 6 7 > then all you have to go is limit the range of your numbers.... eg: just go and list current page + 4 pages, current page num( not link), currentpage - 4 pages.... then add the next previous, adn more or less links should be fairly easy if thats what your trying to do gdlk Link to comment https://forums.phpfreaks.com/topic/52202-code-help-limiting-number-of-pages-listed-on-pagation/#findComment-257518 Share on other sites More sharing options...
BlackenedSky Posted May 20, 2007 Share Posted May 20, 2007 http://www.phpfreaks.com/tutorials/43/0.php Link to comment https://forums.phpfreaks.com/topic/52202-code-help-limiting-number-of-pages-listed-on-pagation/#findComment-257548 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.