Hulio Posted December 3, 2006 Share Posted December 3, 2006 Here's another question considering my paging -system:How could I make the script work like it wouldn't show all the pagenumbers at the same time. I mean if there's like a hundred of pages it would do it more likely this way:<[1] 2 3 4 5...Next > (Showing the first page)or< Prev ...3 4 [5] 6 7...Next > (Showing the page #5)[code]<?phpinclude("MySQL.php");$page_url = "Guestbook.php";mysql_connect($mysql_server,$mysql_user,$mysql_pass);mysql_selectdb($mysql_db);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 = $_GET['Page'];$limit = 5;$result = mysql_query("SELECT count(*) FROM Guestbook");$total = mysql_result($result, 0, 0);$pager = Pager::getPagerData($total, $limit, $page);$offset = $pager->offset;$limit = $pager->limit;$page = $pager->Page;$query = "SELECT * FROM Guestbook ORDER BY Id DESC LIMIT $offset, $limit";$result = mysql_query($query);echo "<div align=\"center\">";if ($page == 1)echo "";elseecho "<font class=\"Basic\"><a href=\"$page_url?Page=" . ($page - 1) . "\">« Prev</a></font>";for ($i = 1; $i <= $pager->numPages; $i++) {if ($i == $pager->Page)echo "<font class=\"Basic\">Page $i</font>";elseecho "<font class=\"Basic\"> <a href=\"$page_url?Page=$i\">$i</a> </font>";}if ($page == $pager->numPages)echo "";elseecho "<font class=\"Basic\"><a href=\"$page_url?Page=" . ($page + 1) . "\">Next »</a></font>";echo "</div>";// Content begins //for($ii = 0; $ii < mysql_numrows($result); $ii++) {echo "<div class=\"H1\">";echo mysql_result($result,$ii,"Topic");echo "</div>";echo "<p class=\"Basic\">";echo wordwrap(nl2br(mysql_result($result,$ii,"Txt")), 60, "\n", 1);echo "</p>";echo "<p class=\"Sender\">";echo mysql_result($result,$ii,"Sender");echo " - ";echo mysql_result($result,$ii,"Time");echo "</p>";}// Content ends //mysql_close();?>[/code] Link to comment https://forums.phpfreaks.com/topic/29297-another-paging-issue/ Share on other sites More sharing options...
Philip Posted December 3, 2006 Share Posted December 3, 2006 http://www.phpfreaks.com/tutorials/147/0.php Link to comment https://forums.phpfreaks.com/topic/29297-another-paging-issue/#findComment-134381 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.