RT,лл
åå¼ç¤ºä¾ä»£ç å¦ä¸ï¼
<?php//æ°æ®åºè¿æ¥
$conn=mysql_connect("localhost","root","root");
if(!$conn){
die("对ä¸èµ·ï¼æ°æ®åºè¿æ¥å¤±è´¥ï¼ ").mysql_errno();
}
//éæ©æ°æ®åº
mysql_select_db("testdb");
//sqlè¯å¥
$sql="SELECT COUNT(*) AS count FROM user";
//æ§è¡sql
$query=mysql_query($sql,$conn);
//对ç»æè¿è¡å¤æ
if(mysql_num_rows( $query)){
$rs=mysql_fetch_array($query);
//ç»è®¡ç»æ
$count=$rs[0];
}else{
$count=0;
}
echo $count;
?>
温馨提示:答案为网友推荐,仅供参考
第1个回答 2012-01-23
select count(*) as a from yourtable where.....
然后再结果数组中用 a为键取值本回答被提问者采纳
然后再结果数组中用 a为键取值本回答被提问者采纳
第2个回答 2012-01-22
$sql = "select count(*) as num from table";
$query = mysql_query($sql);
$row = mysql_fetch_array($query);
echo $row['num'];
$query = mysql_query($sql);
$row = mysql_fetch_array($query);
echo $row['num'];