2010-07-28 56 views
0

我想打印每个帖子一个incresing号码。像每个论坛都有这个。分页和行编号

我目前使用的:

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

可以说我每页打印5后

这是发生了什么:

#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 

我不希望这样,我希望它保持从第一页开始增加最高数字

sql:

SELECT u.group_id, u.username, u.title, p.poster, p.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 

回答

1

的你必须有一个变量确定你的页面。将页码乘以每页元素的数量。 Voila,第N页的第一个元素的唯一ID。

1

,而不是打印$row打印($row + ($page * $pagesize))

+0

计数它不会与页面#1的工作是 – Kirzilla 2010-07-28 15:27:13

+0

它会如果你从0开始计数 – tster 2010-07-28 17:18:13

1

您需要考虑页码。如果你从0开始编号的页面,你需要开始在$ currentPageNumber * $ itemsPerPage

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

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

这将无法正常工作任何页面大于2 – tster 2010-07-28 17:17:57