[英]SQL count not working (with mysql_fetch_assoc();)
我正在尝试为我的网站创建一个管理面板。 我在仪表板上使用此代码来计算用户数(博客帖子等类似):
//get result
$data = mysql_query("SELECT count(user_id) AS total FROM account_users");
$info = mysql_fetch_assoc($data);
//output result
echo "Rows found :" . $info['total'];
当我输入此代码并查看页面时,结果如下:
Rows found :
如您所见,该数字不可见。
我试图执行PHPMyAdmin的SQL部分中的代码,结果为1(并且数据库中有1行,所以是正确的!)
这怎么可能? (你能帮我吗?)
关于第一个评论的更新:我添加了他告诉我的代码,但是并没有更好.....
我现在得到的错误:
Notice: Undefined index: auth in /home/vol9_6/epizy.com/epiz_21854614/admin.ictsupport.ga/htdocs/index.php on line 9
Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/vol9_6/epizy.com/epiz_21854614/admin.ictsupport.ga/htdocs/index.php on line 19
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in /home/vol9_6/epizy.com/epiz_21854614/admin.ictsupport.ga/htdocs/index.php on line 20
Rows found :
Notice: Undefined index: username in /home/vol9_6/epizy.com/epiz_21854614/admin.ictsupport.ga/htdocs/nav.php on line 3
mysql_query已弃用。
使用mysqli_query。 尝试:
$con=mysqli_connect("localhost","my_user","my_password","my_db");
$sql="SELECT count(user_id) AS total FROM account_users";
$result=mysqli_query($con,$sql);
// Associative array
$row=mysqli_fetch_assoc($result);
echo "Rows found :" . $row['total'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.