Php 检查空行查询
事实上,我正在编写一个小的PHP脚本,但我现在面临一个问题。问题是我想检查我的查询返回是否记录这是我的mysqli查询:Php 检查空行查询,php,mysqli,Php,Mysqli,事实上,我正在编写一个小的PHP脚本,但我现在面临一个问题。问题是我想检查我的查询返回是否记录这是我的mysqli查询: $sql = "select * from specs where btitleid=$id and phoneid=$aydi" $check = $conn->query($sql) while($row = $check->fetch_assoc()) {$tocheck = $row['content'];} 我不想检查此查询的行
$sql = "select * from specs where btitleid=$id and phoneid=$aydi"
$check = $conn->query($sql)
while($row = $check->fetch_assoc()) {$tocheck = $row['content'];}
我不想检查此查询的行数以查看它是否为空。我想检查所有$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` != '') ";
使用
if
condition then.@Fred ii-我如何使用if和While?答案如下;我的想法完全正确。@Fred ii-请检查下面对答案的评论。谢谢。要检查它们是否都是空的,您必须为此发出一个查询。除非您希望返回列不为空的行。在我的情况下,您的代码将无法工作,您的代码将检查是否至少有一个空$row['content'],在我的情况下,我希望检查它们是否都为空。谢谢你的帮助。我已经更新了它,所以它会检查所有的行是否都是空的。检查peter的答案它工作得很好,非常感谢你的帮助。