mysql_num_rows – Get number of rows in MySQL result handle

Get number of rows in MySQL result handle, mysql_num_rows – Get number of rows in MySQL result handle, GTechHub

Get number of rows in MySQL result handle, follow the simple process mentioned below. The mysql_num_rows() function returns the number of rows in a database recordset.

mysql_num_rows() function returns FALSE on failure.

Syntax

mysql_num_rows(resource $data)

Warning: This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0

<?php 
### Connect database
mysql_connect("localhost", "db_user", "db_password");
mysql_select_db("database_name");

### Execute database select query
$result_set = mysql_query("SELECT id FROM customer WHERE active = 1");

### Verifying the $result_set content
if(mysql_num_rows($result_set))
{
  ### Result found 
  echo "Result found...";
}
else
{
  ### Empty result found
  echo "Empty result found...";
}

mysql_close();

?>

Response:

If active customer record found:

Result found...

If no active customer:

Empty result found...

Get number of rows in MySQL result handle, mysql_num_rows &#8211; Get number of rows in MySQL result handle, GTechHub

You Might Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *