php计数图像不是所有行只有图像

时间:2016-07-17 16:40:17

标签: php

我想计算图像的数量,但不是所有的行 这是我的功能:

function profile_count_image($user_id) {
    global $Connection;

    $sql_query = mysqli_query($Connection, "SELECT image FROM posts WHERE added_by='$user_id'"); 
    $num_rows = mysqli_num_rows($sql_query);

    return $num_rows;   
}

这就是我在数据库中所拥有的:

dsadsadsad

回声(回归)告诉我:5 ??? (正确是1但显示5)

3 个答案:

答案 0 :(得分:2)

试试这个

$sql_query = mysqli_query($Connection, "SELECT image FROM posts WHERE added_by='$user_id' AND image !=''");

答案 1 :(得分:1)

在查询中添加一个谓词,用于检查图像字段是否为空:

Select image from posts where added_by='$user_id' and image is not null

答案 2 :(得分:1)

变化:

$sql_query = mysqli_query($Connection, "SELECT image FROM posts WHERE added_by='$user_id'");

要:

$sql_query = mysqli_query($Connection, " SELECT image FROM posts WHERE added_by = '$user_id' AND image IS NOT NULL ");