我想计算图像的数量,但不是所有的行 这是我的功能:
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;
}
这就是我在数据库中所拥有的:
回声(回归)告诉我:5 ??? (正确是1但显示5)
答案 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 ");