Dysan Posted March 10, 2008 Share Posted March 10, 2008 Hi, How can the following code be adapted, so that the user can click on a specific page number, instead of having to click the "PREVIOUS" or "NEXT" buttons multiple times? <?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 persons"), 0); $select = "SELECT * FROM persons LIMIT $start, $perpage"; $result = mysql_query($select) or die(mysql_error()); # Dislay your rows here in the loop while($row = mysql_fetch_array($result)) { echo $row['name']." "; echo $row['age']." "; echo $row['sex'].'<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 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.