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.
Move your $stmt->prepare("SELECT event FROM calendar WHERE date = ?")
outside of the foreach loop and
$stmt->close()
outside of foreach loop
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.