Advertisement
puggan

paging whit post_id

May 17th, 2011
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1.     $adjacents = 3;
  2.     $targetpage = "index.php";
  3.     $limit = 4;    
  4.  
  5.     $resource = mysql_query("SELECT count(*) AS antal FROM posts");
  6.     $result = mysql_fetch_assoc($resource);
  7.     $post_count = $result['antal'];
  8.     $page_count = ciel($post_count / $limit);
  9.  
  10.     if(isset($_GET['page'])
  11.     {
  12.         $page = (int) $_GET['page'];
  13.     }
  14.     else if(isset($_GET['post']))
  15.     {
  16.         $resource = mysql_query("SELECT COUNT(*) AS before FROM posts WHERE post_id < " . (int) $_GET['post']);
  17.         $result = mysql_fetch_assoc($resource);
  18.         $post_position = $result['before'];
  19.         page = 1 + floor($post_position / $limit);
  20.     }
  21.     else
  22.     {
  23.         $page = 1;
  24.     }
  25.  
  26.     $page = min($page, $page_count);
  27.     $page = max($page, 1);
  28.  
  29.     $start = ($page - 1) * $limit;  
  30.     $resource = mysql_query("SELECT * FROM posts ORDER BY date ASC LIMIT ".$start.", ".$limit);
  31.     $posts = array();
  32.     while($result = mysql_fetch_assoc($resource))
  33.     {
  34.         $posts[$result['post_id']] = $result;
  35.     }
  36.  
  37.     $prev = $page - 1;                          //previous page is page - 1
  38.     $next = $page + 1;                          //next page is page + 1
  39.     $lastpage = $page_count;
  40.     $lpm1 = $lastpage - 1; 
  41.  
  42.     $pagination = "";
  43.  
  44.     foreach($posts as $post_id => $current_post)
  45.     {
  46.         /* echo html... */
  47.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement