本文介绍了从php中的mysql表中选择count(*)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
mysql_fetch_assoc() mysql_free_result mysql_fetch_row() mysql_fetch_assoc()
mysql_free_result()
mysql_fetch_row()
我可以得到mysql查询结果的值和行。
但我很难得到查询的单个输出。例如:
$ result = mysql_query(SELECT COUNT(*)FROM Students;);我需要显示结果。但我没有得到结果。
我尝试了以下方法:
您需要使用别名来对聚合进行别名,作为关键字,以便从 mysql_fetch_assoc
中调用 $ result = mysql_query(SELECT count(*)as total from Students); $ data = mysql_fetch_assoc($ result); echo $ data ['total'];
I am able to get both the value and row of the mysql query result.
But I am struggling to get the single output of a query. e.g.:
$result = mysql_query("SELECT COUNT(*) FROM Students;");I need the result to display. But I am not getting the result.
I have tried with the following methods:
But I didn't succeed to display (get) the actual value.
解决方案You need to alias the aggregate using the as keyword in order to call it from mysql_fetch_assoc
$result=mysql_query("SELECT count(*) as total from Students"); $data=mysql_fetch_assoc($result); echo $data['total'];
更多推荐
从php中的mysql表中选择count(*)
发布评论