mysql_num_rows
Get the number of rows in the result set.
Function name: mysql_num_rows()
Applicable version: PHP 5.0.0 - PHP 7.0.0 (deprecated)
Usage: The mysql_num_rows() function is used to get the number of rows in the result set.
Syntax: int mysql_num_rows ( resource $result )
parameter:
Return value: Returns the number of rows in the result set, and returns 0 if the result set is empty or error.
Example:
// 连接到MySQL 数据库$link = mysql_connect("localhost", "username", "password"); if (!$link) { die('连接数据库失败: ' . mysql_error()); } // 选择数据库$db_selected = mysql_select_db("database_name", $link); if (!$db_selected) { die ("无法使用指定的数据库: " . mysql_error()); } // 执行查询语句$result = mysql_query("SELECT * FROM table_name", $link); if (!$result) { die('查询失败: ' . mysql_error()); } // 获取结果集中的行数$num_rows = mysql_num_rows($result); echo "结果集中的行数为:" . $num_rows; // 释放结果集mysql_free_result($result); // 关闭数据库连接mysql_close($link);
Notes: