简体   繁体   中英

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

I searched in google and I found the following command:

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. While number of rows in my table is 12 .

The query just returns 1 row. 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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