简体   繁体   中英

How to get total number of row by using this function php mysql?

How to get total number of row by using this function php mysql ?

i use this code for display data from mysql. It's work good,

Buy i want to know can i get total number of row by using this code ?

<?PHP
include("connect.php");
$query = "SELECT * FROM table";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
    $id = $row['id'];
}
?>

试试这个mysql_num_rows ($result)

Use this line of code

<?PHP
include("connect.php");
$query = "SELECT * FROM table";
$result = mysql_query($query) or die(mysql_error());
$number_of_rows = mysql_num_rows($result); // this will return the number of rows found by the $result query. 
echo $number_of_rows;
while($row = mysql_fetch_array($result))
{
    $id = $row['id'];
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM