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

Definition and Usage

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

grammar

mysql_num_rows(data)
parameter describe
data Required. result set. The result set is obtained from a call to mysql_query().

illustrate

mysql_num_rows() returns the number of rows in the result set. This command is only valid for SELECT statements. To get the number of rows affected by an INSERT, UPDATE or DELETE query, use  mysql_affected_rows() .

Tips and Notes

NOTE: If  mysql_unbuffered_query() is used, mysql_num_rows() cannot return the correct value until all rows in the result set have been fetched.

example

<?php
$con = mysql_connect("localhost", "hello", "321");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

$db_selected = mysql_select_db("test_db",$con);

$sql = "SELECT * FROM person";
$result = mysql_query($sql,$con);
echo mysql_num_rows($result);

mysql_close($con);
?>

The output is similar:

3

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324895611&siteId=291194637