Return the number of rows in the result set:
<?php // Assume database username: root, password: 123456, database: CODERCTO $con=mysqli_connect("localhost","root","123456","CODERCTO"); 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("Return %d rows of data in total.",$ rowcount); // Release the result set mysqli_free_result($result);}mysqli_close($con);?>
The mysqli_num_rows() function returns the number of rows in the result set.
mysqli_num_rows( result ) ;
parameter | describe |
---|---|
result | Required. Specifies the result set identifier returned by mysqli_query(), mysqli_store_result(), or mysqli_use_result(). |
Return value: | Returns the number of rows in the result set. |
---|---|
PHP version: | 5+ |