Easy Tutorial
❮ Func Array Product Func Mysqli Options ❯

PHP mysqli_num_rows() Function

PHP MySQLi Reference Manual

Returns the number of rows in the result set:

<?php 
// Assume database username: root, password: 123456, database: tutorialpro 
$con = mysqli_connect("localhost", "root", "123456", "tutorialpro"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 

$sql = "SELECT name, url FROM websites ORDER BY alexa;";

if ($result = mysqli_query($con, $sql))
{
    // Return the number of records
    $rowcount = mysqli_num_rows($result);
    printf("Total of %d rows returned.", $rowcount);
    // Free the result set
    mysqli_free_result($result);
}

mysqli_close($con);
?>

Definition and Usage

The mysqli_num_rows() function returns the number of rows in the result set.


Syntax

Parameter Description
result Required. Specifies a result set identifier returned by mysqli_query(), mysqli_store_result(), or mysqli_use_result().

Technical Details

Return Value: Returns the number of rows in the result set.
PHP Version: 5+
--- ---
❮ Func Array Product Func Mysqli Options ❯