bnds.net
当前位置:首页 >> php sElECt Count >>

php sElECt Count

select count(*) as total from tab 用的时候用 rs("total") 就OK $qid = mysql_query("select count(*) as total from tab "); $res = mysql_fetch_array($qid); $count = $res['total'];

首先count查询的结果只有一条 $res=$db->query('select count(*) from table'); $row=$res->fecth(); $row[0]就是count的结果

取值示例代码如下:

Select count(id) as c from xx;

因为别的查询出来是行的集合,而count查询出来只有一个聚合的值,不是sql出错,而是后续处理的php代码出错

据php手册的相关资料,mysql_fetch_row 比 mysql_fetch_array 稍快。 示例代码如下: $query = "select count(*) from test where testid=".$_POST['testid']; $result=mysql_query($query); list($num) = mysql_fetch_row($result);

Example #2 count() 的递归例子(PHP >= 4.2.0)参见 is_array(),isset() 和 strlen()。

count()是一种聚合函数,返回SELECT语句检索到的行中非NULL值的数目

//不知道你select()和count()具体是什么样的select events_address_1 from events group by events_address_1select count(events_address_1) from events group by events_address_1

多种办法: 第一,直接在sql语句中用count获得 例如:$result = mysql_queryj("select count(*) as num from ... ..."); $r = mysql_fetch_array($result); $num = $r["num"]; 直接得到num值就行了; 第二、用mysql_num_rows $result = mysql_qu...

网站首页 | 网站地图
All rights reserved Powered by www.bnds.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com