简体   繁体   English

如何计算表格中的所有行

[英]How can I count all rows that there are in a table

I searched in google and I found the following command: 我在google中搜索,发现以下命令:

SELECT COUNT(*) FROM table_name 

And I used the above code as follows to count all rows that there are in a table. 我使用上面的代码如下,对表中的所有行进行计数。

$number = mysqli_query($connection,"SELECT COUNT(*) FROM table_name");
$rows = mysqli_num_rows($number);
echo $rows;

But when I see the result using the echo command, I see the result as the 1 value. 但是,当我使用echo命令查看结果时,将结果视为1值。 While number of rows in my table is 12 . 而我的表中的行数是12

The query just returns 1 row. 查询仅返回1行。 That row contains the count of rows in it. 该行包含其中的行数。 You need to fetch the row to get the answer, just like you do to get the results from any other query. 您需要获取行以获取答案,就像从任何其他查询中获取结果一样。

$result = mysqli_query($connection,"SELECT COUNT(*) AS count FROM table_name");
$row = mysqli_fetch_assoc($result);
$rows = $row['count'];
echo $rows;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM