计算mysql中的行数?
如何用php统计mysql数据库表的行数?
如果数据库中有 5 行,它们的编号显示如下(粗体):
<块引用>所有列是:5
1 行 1
2 行 2
3 行 3
4 行 4
5 第5行
How to count the number of rows in mysql database tables with php?
if have in database 5 rows, they number show like this(bold):
all columns is: 5
1 row1
2 row2
3 row3
4 row4
5
row5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需使用这个 SQL 查询:
如果您想知道另一个查询返回了多少行,您可以使用 PHP mysql_num_rows 函数。 (您也可以为处理的每一行增加一个计数器,但如果您需要在枚举结果之前知道记录数,则此函数会很方便。)
Just use this SQL query:
If you want to know how many rows were returned by another query, you can use the PHP mysql_num_rows function. (You could also just increment a counter for each row you process, but this function is handy if you need to know the number of records prior to enumerating the results.)
您可以使用此
$num_rows
作为 table_name 中的总行数然后您可以执行以下操作
echo 'The number of rows in table_name is '.$num_rows< /代码>;
You can use this
$num_rows
would be the total rows in table_nameThen you can just do this
echo 'The number of rows in table_name is '.$num_rows
;这个查询应该可以满足您的需要:
结果集将是
假设您有 5 行。
为了手动计算每一行并显示其索引(不使用 ID),我会做类似的事情
This query should do the trick for you:
The result set would be
Assuming you have 5 rows.
In order to manually count each row and display its index (without using ID), I would do something like