事实上我正在处理一个小的PHP脚本,但我现在面临一个问题。问题是我想检查我的查询是否返回记录这是我的mysqli查询:
$sql = "select * from specs where btitleid=$id and phoneid=$aydi"
$check = $conn->query($sql)
while($row = $check->fetch_assoc()) {$tocheck = $row['content'];}
我不想检查此查询的行数以查看它是否为空。我想检查所有$row['content']
是否为空。
答案 0 :(得分:0)
这个怎么样:
$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
}
答案 1 :(得分:0)
使用==
while ($row = $check->fetch_assoc()) {
if ($row['content'] == '') {
... code here
}
}
答案 2 :(得分:0)
仅返回内容列不为空的记录 -
$sql = "SELECT * FROM `specs` WHERE `btitleid` = $id AND `phoneid` = $aydi AND (`content` IS NOT NULL OR `content` != '') ";