Hello.. Can any one help me creating a dynamic pagination script for sql entries i made this simple paging script Code: ( text ) it displays all the following: Select a Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Next-> Can anyone help me to shorten the list of displaying page links? I want to do some like this: 1 2 3 4 5 6 7 8 9 10 Next-> and if the vistor is looking the page no 10 it should look like this <-Previous 11 12 13 14 15 16 17 18 Next-> Thank's
You need to limit your input for example <?php // example count $pages = 20; // check if more pages then 10 if ($pages > 10) { $toPages = 10; } elseif ($pages < 10) { $toPages = $pages; } else { $toPages = $pages; } // from position &from=page (7) if (isSet($_GET['from']) && is_numeric($_GET['from'])) { if ($_GET['from'] > $pages) { $from = $pages - 5; } elseif ($_GET['from'] < 0) { $from = 0; } else { $from = $_GET['from']; } } else { $from = 0; } if ($from - ($toPages/2) < 0) { $startPages = 1; } else { $startPages = $from - ($toPages/2); } echo '<a href="index.php">First</a> '; for ($x = $startPages; $x < $startPages + $toPages; $x++) { echo '<a href="index.php?from=' . $x . '">'; if ($x == $from) { // current page echo '<strong>' . $x . '</strong>'; } else { // show page number echo $x; } echo '</a> '; } echo '<a href="index.php?from=' . $pages . '">Last</a>'; ?> PHP: Easy page navigation..
algorithms on paper == writing the basic logic on paper in your native language * like get number of records in data base * divide by records per page to get number pages * if current page more than 1 then show previous link and links from current page - 10 to current page that are more than 0 * show links current page +1 to current page + 10 (but stop if u reach Max page) * show next link if there are more pages then current page so this is basic algorithm to make pseudo code write with line numbers and go to statements ... and convert them to pseudo code then php