PHP mysql_num_rows() Function Example

PHP mysql_num_rows() Function Example


Posted in : PHP Posted on : February 21, 2011 at 6:23 PM Comments : [ 0 ]

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 

Download Example Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics