mysqli_num_rows returns 1 no matter what(mysqli_num_rows 返回 1 无论如何)
本文介绍了mysqli_num_rows 返回 1 无论如何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在 phpMyAdmin 中进行 SQL 搜索(用变量代替实际值)时,它返回正确的行号,但是当使用 PHP 返回这个值时,无论如何它总是返回 1.提前致谢.
When I do a SQL search in phpMyAdmin (substituting the variable for the actual value) it returns the correct row number but when using PHP to return this value it always returns 1 no matter what. Thanks in advance.
function user_exists($username) {
$link = mysqli_connect('localhost','root','','test');
$username = sanitize($username);
$query = mysqli_query($link, "SELECT COUNT(`user_id`) FROM `new_base` WHERE `username`='$username'");
$row_cnt = mysqli_num_rows($query);
echo $row_cnt;
mysqli_free_result($query);
mysqli_close($link);
}
推荐答案
当你使用 COUNT(*)
你即使计数为零也总是返回一行.
你要么:
- 想去掉
count(*)
然后使用mysqli_num_rows()
或 - 获取
count(*)
的结果
- Want to remove the
count(*)
and then usemysqli_num_rows()
or - Get the result of
count(*)
.
$row = mysqli_fetch_assoc($query);
echo $row['COUNT(`user_id`)'];
这篇关于mysqli_num_rows 返回 1 无论如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:mysqli_num_rows 返回 1 无论如何


基础教程推荐
猜你喜欢
- 将变量从树枝传递给 js 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- php中的foreach复选框POST 2021-01-01
- php中的PDF导出 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01