How to query the number of mysql records in php: 1. Use the "mysql_num_rows" function to query the number of mysql records; 2. Query the number of mysql records by modifying the query statement and using "COUNT(*)" as the query content.
Recommended: "PHP video tutorial" "php mysql"
PHP query statement ,Return the total number of records
PHP query statement, there are two methods to obtain the total number of records queried.
MySQLi process-oriented approach
$sql = "SELECT id, firstname, lastname FROM MyGuests"; $result = mysqli_query($conn, $sql); num_rows=mysqli_num_rows($result);
First, use the mysql_num_rows function, example code:
<?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"; ?>
The second is to modify the query statement, using COUNT(*) as the query content, example Code:
<?php $link = mysql_connect("localhost", "mysql_user", "mysql_password"); mysql_select_db("database", $link); $result = mysql_query("SELECT COUNT(*) FROM table1", $link); list($num_rows) = mysql_fetch_row($result); echo "$num_rows Rows\n"; ?>
The above is the detailed content of How to query the number of mysql records in php. For more information, please follow other related articles on the PHP Chinese website!