php8.5
Home/ Manual/ mysql / functions/ mysql_num_rows

mysql_num_rows

PHP function Edit on GitHub ✎

(PHP 4, PHP 5)

Get number of rows in result

Note mysqli_num_rowsmysqli_stmt_num_rowsPDOStatement::rowCount

Description

mysql_num_rows(resource $result): int|false

Retrieves the number of rows from a result set. This command is only valid for statements like SELECT or SHOW that return an actual result set. To retrieve the number of rows affected by a INSERT, UPDATE, REPLACE or DELETE query, use mysql_affected_rows().

Parameters

Return Values

The number of rows in a result set on successFalseforfailure.

Examples

mysql_num_rows() example

php
<?php

$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);

$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";

?>

Notes

Note

If you use mysql_unbuffered_query(), mysql_num_rows() will not return the correct value until all the rows in the result set have been retrieved.

Note

Alias mysql_numrows()

See Also

Source: reference/mysql/functions/mysql-num-rows.xml · from the official PHP manual (php/doc-en)