Dysan Posted January 1, 2008 Share Posted January 1, 2008 I have come up with the following code, that limits the amounts of data displayed per page to only 2 records. Depending on the number of records on a page, a NEXT and PREVIOUS link is displayed. How do I add page number links to the code, to enable the user to navigate directly to a particular page, without the need of scanner through endless amounts of page until the required page is displayed? The image at the following URL, is what I'm after! http://notoon.free.fr/images/forum/20070103_pagination.gif <?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die(mysql_error()); } mysql_select_db("db", $con); $perpage = 2; $start = (isset($_GET['id'])) ? $_GET['id'] : 0; $TotalRec = mysql_result(mysql_query("SELECT COUNT(*) FROM person"), 0); $select = "SELECT * FROM person LIMIT $start, $perpage"; $result = mysql_query($select) or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo $row['FirstName']." "; echo $row['LastName'].'<br />'; } if($start == 0) { echo "PREVIOUS"; } else { echo '<a href="pagination.php?id=' . ($start - $perpage) . '">'."PREVIOUS".'</a>'; } $page = ($_GET['id'] / $perpage) + 1; $total = ceil($TotalRec / $perpage); if($start + $perpage >= $TotalRec) { echo "NEXT"; } else { echo '<a href="pagination.php?id=' . ($start + $perpage) . '">'."NEXT".'</a>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/83966-page-numbers-pagination/ Share on other sites More sharing options...
sKunKbad Posted January 1, 2008 Share Posted January 1, 2008 Search around for pagination classes. I'm not talking about tutorials, I'm talking about OOP. The work has been done, so don't re-invent the wheel. Quote Link to comment https://forums.phpfreaks.com/topic/83966-page-numbers-pagination/#findComment-427320 Share on other sites More sharing options...
Dane Posted January 1, 2008 Share Posted January 1, 2008 This should help you. I just created it in a few minutes so modifiying the colours etc to how you like will work. <style type="text/css"> <!-- .tableoutline { FONT-SIZE: 8pt; COLOR: #000000; FONT-FAMILY: Arial; BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid; } --> </style> <table width="200" border="0" cellpadding="1" cellspacing="1"> <tr> <td width="40" class="tableoutline" onmouseover='this.style.background="#c3c3c3"; return true' onmouseout='this.style.background="#FFFFFF"; return true'>Prev</td> <td width="20" class="tableoutline" onmouseover='this.style.background="#c3c3c3"; return true' onmouseout='this.style.background="#FFFFFF"; return true'>1</td> <td width="20" class="tableoutline" onmouseover='this.style.background="#c3c3c3"; return true' onmouseout='this.style.background="#FFFFFF"; return true'>2</td> <td width="20" class="tableoutline" onmouseover='this.style.background="#c3c3c3"; return true' onmouseout='this.style.background="#FFFFFF"; return true'>3</td> <td width="40" class="tableoutline" onmouseover='this.style.background="#c3c3c3"; return true' onmouseout='this.style.background="#FFFFFF"; return true'>Next</td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/83966-page-numbers-pagination/#findComment-427383 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.