【问题标题】:Counting specific records MySQL计算特定记录 MySQL
【发布时间】:2019-08-29 20:59:46
【问题描述】:

我想在 PHP MySQL 中显示状态为 1(见代码)的用户数。

<?php
// something like this
$result = mysqli_query($mysqli, "SELECT COUNT(*) FROM users WHERE status = '1'");
echo "$result";
?>

【问题讨论】:

  • 请添加您的代码
  • 您尝试过您发布的内容吗?

标签: php mysql database search


【解决方案1】:

试试这个:

$query = "SELECT COUNT(*) as countvar FROM users where status = '1'";

$result = mysqli_query($con,$query);

$row = mysqli_fetch_array($result);

$count= $row['countvar '];

【讨论】:

  • 感谢您的帮助,但我收到以下错误:注意:未定义的变量:第 273 行 C:\xampp\htdocs\watermeters\index.php 中的 con 致命错误:未捕获的错误:调用成员函数 query() on null in C:\xampp\htdocs\watermeters\index.php:273 堆栈跟踪:#0 {main} 在第 273 行的 C:\xampp\htdocs\watermeters\index.php 中抛出
  • 变量 $con 必须替换为您的 mysqli 连接变量 - 在您的情况下为 $mysqli
  • 谢谢,现在没有错误了,我如何调用(显示)结果,如 echo "" 等,我是个老家伙,正在学习
  • 没关系,哈哈,非常感谢你帮它解决了太多啤酒哈哈
猜你喜欢
  • 2012-09-12
  • 2012-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-22
  • 1970-01-01
  • 1970-01-01
  • 2022-01-13
相关资源
最近更新 更多