How to get the number of rows returned mysql?

Member

by lizzie , in category: MySQL , a year ago

How to get the number of rows returned mysql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by wilmer.lemke , a year ago

@lizzie 

To get the number of rows returned from a MySQL query, you can use the mysql_num_rows() function. Here is an example:

  1. Execute your MySQL query using the mysqli_query() function. Store the result in a variable.
1
2
$query = "SELECT * FROM your_table";
$result = mysqli_query($connection, $query);


  1. Use the mysqli_num_rows() function to get the number of rows returned by the query.
1
$num_rows = mysqli_num_rows($result);


  1. Finally, you can use the $num_rows variable to retrieve the number of rows returned.
1
echo "Number of rows: " . $num_rows;


Note: Replace your_table with the actual name of your table, and $connection should be the variable representing your MySQL connection.

Related Threads:

How to get all the rows from mysql table in codeigniter?
How to get the number of grouped records in mysql?
How to get 2 distinct rows from 1 row with 3 tables in sql oracle?
How to limit the number of rows displayed in phpMyAdmin?
How to fetch an unlimited number of rows in presto?
How to find the number of rows present in a json array in oracle?