The mysql_num_rows() function is used to find the number of rows in a recordset.
PHP mysql_num_rows() Function Example:
The mysql_num_rows() function is used to find the number of rows in a recordset. The mysql_num_rows() function return number of rows in a recordset on success or false for failure.
Syntax:
mysql_num_rows(result)
where result is required specified which data pointer to use.
Example:
<?php $connection = mysql_connect("localhost", "root", "root"); if (!$connection) { die('PHP Mysql database connection could not connect : ' . mysql_error()); } $db_selected = mysql_select_db("php_mysql", $connection); $sql_query = "SELECT * FROM user"; $result = mysql_query($sql_query, $connection); echo "Number of rows : " . mysql_num_rows($result); mysql_close($connection); ?>
The database 'user' table records id:
After running this example the browser output is:
Output:
Number of rows : 2
[ 0 ] Comments