检查空行查询

Check empty rows query

事实上,我正在编写一个小的 PHP 脚本,但我正面临一个问题 now.The 问题是我想检查我的查询 return 是否记录了这是我的mysqli 查询:

    $sql = "select * from specs where btitleid=$id and phoneid=$aydi"
    $check = $conn->query($sql)
    while($row = $check->fetch_assoc()) {$tocheck = $row['content'];}

我不想检查此查询的行数以查看它是否 null.I 想检查是否所有 $row['content'] 都是空的。

这个怎么样:

$sql = "select * from specs where btitleid=$id and phoneid=$aydi";
$check = $conn->query($sql);

$contentAllEmpty = true;
while ($row = $check->fetch_assoc()) {
    if (strlen($row['content']) > 0) {
        $contentAllEmpty = false;
    }
}

if ($contentAllEmpty) {
    //do something
}

使用==

while ($row = $check->fetch_assoc()) {
if ($row['content'] == '') {
    ... code here
   }
}

仅获取内容列不为空的记录 -

$sql = "SELECT * FROM `specs` WHERE `btitleid` = $id AND `phoneid` = $aydi AND (`content` IS NOT NULL OR `content` != '') ";