PHP和MySQL:返回的行数 [英] PHP and MySQL: Number of rows returned

查看:247
本文介绍了PHP和MySQL:返回的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);

推荐答案

就像Michiel所说的那样,mysql_num_rows()做这项工作.但是,如果要使用一个数组处理多个行,也可以使用count().

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.

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

这篇关于PHP和MySQL:返回的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆