php - 分页和行编号

标签 php mysql

我想在每个帖子中打印一个递增的数字。每个论坛都有这个。

我目前使用这个:

$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

最佳答案

您必须有一个变量来标识您所在的页面。将页码乘以每页的元素数。瞧,第 N 页第一个元素的唯一 ID。

关于php - 分页和行编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3354417/

相关文章:

php - 两个查询与一个查询,性能

php - 一个讨厌的砌体 IE 错误

php - 使用 JSON 发送二进制文件内容

PHP/regex解析NGINX错误日志

mysql - 更新多行,增加值(value)。(不是autoinc。)

PHP支持聊天系统

Mysql显示记录甚至没有结果

php - 如何使用 php api 创建 mmjmenu?

php - cURL 通过命令行工作,但不能在 PHP Curl 中工作

来自两次连接挑战的 MySQL 'multiple rows'