puggan icon

paging whit post_id

puggan | PRO | 05/17/11 10:25:37 AM UTC | 0 ⭐ | 619 👁️ | Never ⏰ | []
PHP |

1.17 KB

|

None

|

0 👍

/

0 👎

    $adjacents = 3;
    $targetpage = "index.php";
    $limit = 4;     
 
    $resource = mysql_query("SELECT count(*) AS antal FROM posts");
    $result = mysql_fetch_assoc($resource);
    $post_count = $result['antal'];
    $page_count = ciel($post_count / $limit);
 
    if(isset($_GET['page'])
    {
        $page = (int) $_GET['page'];
    }
    else if(isset($_GET['post']))
    {
        $resource = mysql_query("SELECT COUNT(*) AS before FROM posts WHERE post_id < " . (int) $_GET['post']);
        $result = mysql_fetch_assoc($resource);
        $post_position = $result['before'];
        page = 1 + floor($post_position / $limit);
    }
    else
    {
        $page = 1;
    }
 
    $page = min($page, $page_count);
    $page = max($page, 1);
 
    $start = ($page - 1) * $limit;  
    $resource = mysql_query("SELECT * FROM posts ORDER BY date ASC LIMIT ".$start.", ".$limit);
    $posts = array();
    while($result = mysql_fetch_assoc($resource))
    {
        $posts[$result['post_id']] = $result;
    }
 
    $prev = $page - 1;                          //previous page is page - 1
    $next = $page + 1;                          //next page is page + 1
    $lastpage = $page_count;
    $lpm1 = $lastpage - 1;  
 
    $pagination = "";
 
    foreach($posts as $post_id => $current_post)
    {
        /* echo html... */
    }

Comments