开发者

pagination and row numbering

开发者 https://www.devze.com 2023-01-09 10:37 出处:网络
I wanna print a incresing number with each post. Like every forum has this. I currently use this: $i = 0; while ($post = mysql_fetch_assoc($rs)): $i++;

I wanna print a incresing number with each post. Like every forum has this.

I currently use this:

$i = 0; while ($post = mysql_fetch_assoc($rs)): $i++;

Lets say i print 5 post per page

This is what happens:

#1 First post
#2 2nd post
#3 3rd post
#4 4th post
#5 5th post

Then you go to page to 2

#1 6th post
#2 7th post
#3 8th post
#4 9th post
#5 10th post

I dont want that, I want it to keep increse highest number from first page

The sql:

SELECT u.group_id, u.username, u.title, p.poster, p开发者_如何学Go.message, p.thread_id, g.g_title, g.g_user_title FROM posts AS p 
        INNER JOIN users AS u ON u.id = p.poster 
        INNER JOIN groups AS g ON g.g_id = u.group_id
        WHERE p.thread_id = $id
        LIMIT $startIndex, $perPage


You must have a variable identifying which page you're on. Multiply the page number by the number of elements per page. Voila, the unique ID of the first element of page N.


Instead of printing $row print ($row + ($page * $pagesize))


you need to take the page number into account. if you start numbering your pages with 0 you need to start counting at $currentPageNumber * $itemsPerPage


if ($page == 1) {
  $ex_page = 0;
} else {
  $ex_page = $page;
}

$big_post_number = $row_num + $ex_page * $items_per_page;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号