以下代码仅返回一个结果。其余五项结果为空白。我怎样才能返回所有行?
foreach($dates as $date){
if($stmt->prepare("SELECT event FROM calendar WHERE date = ?")) {
$stmt->bind_param('i',$date);
$stmt->execute();
$stmt->bind_result($event);
$stmt->store_result();
while($stmt->fetch()) {
echo $event;
}
$stmt->close();
}
}
答案 0 :(得分:7)
您在第一次执行foreach循环时关闭了预准备语句。
将您的$stmt->prepare("SELECT event FROM calendar WHERE date = ?")
移到foreach循环之外并
$stmt->close()