sayedsohail Posted March 27, 2007 Share Posted March 27, 2007 Hi Everyone, My pagination works fine, i would like to add <A-B-C-D-E-F-G-H..-Z> links at the bottom of the page, can you suggest any improvement to the following script below: // how many rows to show per page $rowsPerPage = 10; // by default we show first page $pageNum = 1; // if $_GET['page'] defined, use it as page number if(isset($_GET['page'])) { $pageNum = $_GET['page']; } // counting the offset $offset = ($pageNum - 1) * $rowsPerPage; $query = "SELECT id, make, model FROM models_view ORDER BY make LIMIT $offset, $rowsPerPage"; $result = mysql_query($query) or die('Error, query failed'); /* (number of records) */ $test_rows = mysql_num_rows($result); if ($test_rows == 0) { echo "<h4>Sorry there are ($test_rows) models in the database. Please insert models.\n</h4>"; exit; } else { // Perform the rest of the query i.e., display records 24th March 2007 //print the form ?> <form name='myform' method='post'><table name='two' border='1'><tr align='center'> <th class='empty1'></th><th class='empty1'>Make</th><th class='empty1'>Model</th> </tr> <?php $i = 1; while(list($id, $make, $model) = mysql_fetch_array($result)) { print"<td align='center'>$make</td>"; print"<td align='center'>$model</td>"; $i= $i + 1; } echo '</table>'; echo '<br>'; // how many rows we have in database $numrows = $row['numrows']; // how many pages we have when using paging? $maxPage = ceil($numrows/$rowsPerPage); $self = $_SERVER['PHP_SELF']; // creating 'previous' and 'next' link // plus 'first page' and 'last page' link // print 'previous' link only if we're not // on page one if ($pageNum > 1) { $page = $pageNum - 1; $p1 =1; ?> <input type="button" name="Previous" value="Prev" onclick="javascript:void(location.href = '<?php print $self.'?page='.$page; ?>')"/> <input type="button" name="First" value="First" onclick="javascript:void(location.href = '<?php print $self.'?page='.$p1; ?>')"/> <?php } else { ?> <button.Previous = disabled> <button.First = disabled> <?php } if ($pageNum < $maxPage) { $page = $pageNum + 1; ?> <input type="button" name="Next" value="Next" onclick="javascript:void(location.href = '<?php print $self.'?page='.$page; ?>')"/> <input type="button" name="Last" value="Last" onclick="javascript:void(location.href = '<?php print $self.'?page='.$maxPage; ?>')"/> <?php } else { ?> <button.Next = disabled> <button.Last = disabled> <?php } // print the page navigation link echo $first . $prev . " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " . $next . $last; echo "<br> "; echo "</form>"; 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.