PHP 和 MySQL:返回的行数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5140298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:54:54  来源:igfitidea点击:

PHP and MySQL: Number of rows returned

phpmysqlsqlmysql-num-rows

提问by tee

How can I see how many rows the following query returns?

如何查看以下查询返回的行数?

mysql_select_db($database_aoldatabase, $aoldatabase);

$query1 = "select * from sale where secid  = $invoiceno ";
$query2 = "select * from sale where secid  = $invoiceno ";


$maxa = mysql_query ($query1)
    or die ("Query '$query' failed with error message: \"" . mysql_error () . '"');
$maxa2 = mysql_query ($query2)
    or die ("Query '$query' failed with error message: \"" . mysql_error () . '"');

$row = mysql_fetch_array($maxa);
$row2 = mysql_fetch_array($maxa2);

回答by Eduard7

Like Michiel said, mysql_num_rows()do the job. But if you want to work with more than one rows using an array, you can use count()too.

就像米歇尔说的,mysql_num_rows()做这份工作。但是如果你想使用数组处理多行,你也可以使用count()

$data = array();
while($row = mysql_fetch_array($maxa, MYSQL_ASSOC)) {
  $data[] = $row;
}
$count1 = mysql_num_rows($maxa);
$count2 = count($data);

回答by Michiel Pater

Use the function mysql_num_rows()

使用功能 mysql_num_rows()

Have a look at: http://nl3.php.net/manual/en/function.mysql-num-rows.php

看看:http: //nl3.php.net/manual/en/function.mysql-num-rows.php