0)) ? intval($_GET['page']) : 1; $view = (isset($_GET['view']) && ($_GET['view'] > 0)) ? intval($_GET['view']) : 10; // Create our fake data to paginate on, just use the alphabet $data = range('a', 'z'); // Now, chunk the data into equal sized pieces, based upon the view. $pages = array_chunk($data, $view, true); // Now output the chunk of data that was asked for: echo "
The results are:
\n\n";
foreach($pages[$page - 1] as $num => $datum) {
echo $num + 1, ". {$datum}
\n";
}
echo "
Switch to page: |'; $get = $_GET; foreach(range(1, count($pages)) as $p) { // If this is the current page: if ($page == $p) { echo " {$p} |"; } else { // We need to give them their option - First generate the URL needed // We want to duplicate any query string given to us, but replacing // any pagination values with our new page. Easiest is to take a // current copy of get, update it for our values, then recreate it. $get['page'] = $p; $query = http_build_query($get); echo " {$p} |"; } } echo "
\n"; // Now let's give some options to change how many results we see per page: $options = array(3, 5, 10, 50); // Make a new copy of the $_GET array to play with again $get = $_GET; // Always set page to 1 when making a change to the number of results: unset($get['page']); // And let's output the options in the same manner as the pages: echo 'Results per page: |'; foreach($options as $o) { // If the current option: if ($o == $view) { echo " {$o} |"; } else { // Give the new option, again by regenerating the GET $get['view'] = $o; $query = http_build_query($get); echo " {$o} |"; } } echo "
\n"; ?>