Advertisement
puggan

page numbering

May 6th, 2011
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. <?php
  2.     //$row['guide'] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaa#PAGE_BREAK#bbbbbbbbbbbbbbbbbbbbbbbbb#PAGE_BREAK#ccccccccccccccccccccccccccc";
  3.     //$_GET['page']=2;
  4.  
  5.     /* visa sidan */
  6.     $pages = explode('#PAGE_BREAK#',$row['guide']);
  7.  
  8.     /* fetch the page nr from the url */
  9.     $page_nr = (int) $_GET['page'];
  10.  
  11.     /* lägsta tillåtna är 1 */
  12.     $page_nr = max(1, $page_nr);
  13.  
  14.     /* högsta är samma som antal sidor */
  15.     $page_nr = min($page_nr, count($pages));
  16.  
  17.     /* finns det mer än 1 sida? */
  18.     if(count($pages) > 1)
  19.     {
  20.         /* Make a list whit links for all pages */
  21.         $page_links = array();
  22.         foreach(range(1, count($pages)) as $page_link_nr)
  23.         {
  24.             $page_links[$page_link_nr] = "<a href='?page={$page_link_nr}'>{$page_link_nr}</a> ";
  25.         }
  26.  
  27.         /* replace the link for the current page */
  28.         $page_links[$page_nr] = "<b>{$page_nr}</b>";
  29.  
  30.         /* print all links whit | between */
  31.         echo implode(" | ", $page_links);
  32.     }
  33.  
  34.     /* echo the page */
  35.     echo $pages[$page_nr-1];
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement