如何获取PHP中的select count(*)查询的结果? [英] How to get the result of a select count(*) query in PHP?
本文介绍了如何获取PHP中的select count(*)查询的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有此查询可在PHP中使用:
I have this query to use in PHP:
mysql_query("select count(*) from registeredUsers where email=".$_SESSION["username"]);
当我使用echo
打印结果时,什么也没打印.以上语句的返回值到底是什么?
When I use echo
to print out the result, nothing gets printed. What exactly is the return value from the above statement?
推荐答案
您的代码不包含任何提取语句.作为另一个答案,您需要在$_SESSION["username"]
周围加上单引号.
Your code doesn't include any fetch statement. And as another answer notes, you need single quotes around $_SESSION["username"]
.
$result = mysql_query("select count(*) from registeredUsers where email='{$_SESSION['username']}'");
// Verify it worked
if (!$result) echo mysql_error();
$row = mysql_fetch_row($result);
// Should show you an integer result.
print_r($row);
这篇关于如何获取PHP中的select count(*)查询的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文