有没有办法判断使用这种样式的while循环之前是否有结果?
$stmt = $mysqli->prepare("SELECT * FROM items WHERE type = ?");
$stmt->bind_param('s', $type);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($one,$two,$three);
while ($stmt->fetch()) {
}
我想在 while 循环之前和之后做一些事情,但我不想查询两次。
最佳答案
检查选中的行数:$stmt->num_rows
所以你可能会这样做:
if($stmt->num_rows > 0){
...
}
关于Php MySql While 循环如果有结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23982652/