我正在尝试为我的网站创建一个管理面板。我在仪表板上使用此代码来计算用户数量(博客帖子等也是如此)。
//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
答案 0 :(得分:0)
不建议使用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'];