How to get the number of rows returned mysql?

Member

by lizzie , in category: MySQL , 4 months ago

How to get the number of rows returned mysql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by wilmer.lemke , 4 months 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.