如何使用这个函数php-mysql来获取总行数?
我使用这段代码来显示mysql中的数据。效果不错,
购买我想知道我可以通过使用这个代码获得总行数吗?
<?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)
使用这行代码
<?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'];
}
?>