[英]PHP Prepared Statement Foreach Loop
The code below only returns one result. 以下代码仅返回一个结果。 The remaining five results are blank. 其余五项结果为空白。 How can I return all rows? 我怎样才能归还所有行?
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();
}
}
You closed the prepared statement in the first execution of foreach loop. 您在第一次执行foreach循环时关闭了预准备语句。
Move your $stmt->prepare("SELECT event FROM calendar WHERE date = ?")
outside of the foreach loop and 在foreach循环之外移动$stmt->prepare("SELECT event FROM calendar WHERE date = ?")
$stmt->close()
outside of foreach loop 在foreach循环之外的$stmt->close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.