php - mysql_num_rows 返回 1

标签 php mysql

为什么下面的代码返回 1,尽管字段 group_members 中没有元素?

$conn = mysql_connect($host,$user,$pass);

@mysql_select_db($db);

$sql = "
    SELECT 
        group_members
    FROM
        tbl_group
    WHERE
        group_id = '6'      
";

$res = mysql_query($sql);

$rows = mysql_num_rows($res);

echo $rows;

?>

最佳答案

您编写的 SQL 将选择所有具有 group_id = 6 的行,然后返回字段 group_members 的值而不考虑内容。要得到你想要的,请尝试:

SELECT group_members FROM tbl_group WHERE group_id = 6 AND group_members <> '' // Depending on type might also be <> NULL or <> 0

关于php - mysql_num_rows 返回 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6555700/

相关文章:

php - 是什么导致 undefined index 错误?

php - 检查记录是否存在于php中

mysql - 获取 mysql 中不同重复 ID 的计数

php - 如何在 facebook 等 Web 应用程序中实现线程消息

PHP脚本错误

php - 在 PHP 脚本之间传递上传的文件

php - laravel 将未定义的 url 路由到特定 Controller

php - 使用Doctrine2进行SELECT时如何自动将mysql的SET转换为其整数?

php - 从数据库填充数组,在内部搜索并提取字符串

php - Laravel 5.1 上传和保存从表单发送的Base64图像