从php中的mysql表中选择count(*) [英] select count(*) from table of mysql in php
本文介绍了从php中的mysql表中选择count(*)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以同时获取mysql查询结果的值和行.
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.
我尝试了以下方法:
mysql_fetch_assoc()
mysql_free_result()
mysql_fetch_row()
但我没有成功显示(获取)实际值.
But I didn't succeed to display (get) the actual value.
推荐答案
为了从 mysql_fetch_assoc
调用它,你需要使用 as
关键字为聚合添加别名>
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(*)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文