PHP mysqli_num_rows() Function

PHP mysqli_num_rows() function returns the number of rows in a result set. This command is only valid for statements like SELECT or SHOW that return an actual result set.

Syntax

int mysqli_num_rows(result);

mysqli_num_rows() Function Parameter

ParameterDescription
result :Required parameter. The result resource that is being evaluated. This result comes from a call to mysql_query().

mysqli_num_rows() Function Return Value

Return Values :Returns the number of rows in a result set on success or FALSE on failure.

mysqli_num_rows() Function Example

<?php
$con = mysqli_connect("localhost","user","password","db");

if (mysqli_connect_errno())
{
	echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql = "SELECT fname,lname FROM employee";
$result = mysqli_query($con, $sql);

echo mysql_num_rows($result);
mysqli_free_result($result);

mysqli_close($con);
?>