gpt4 book ai didi

PHP PDO 仅显示第一个结果

转载 作者:行者123 更新时间:2023-11-29 21:49:01 25 4
gpt4 key购买 nike

我试图显示已上传到我的网站上的所有照片,但我只能显示第一行数据。谁能帮我解决这个问题。

<?php
$sql1 = "SELECT * FROM event";
//$query1 = mysqli_query($connect, $sql);
$result = $db->prepare($sql1);
$result->execute();
while($albumId = $result->fetch(PDO::FETCH_ASSOC)){
$ID = $albumId['eventID'];
$albm = $albumId['eventName'];

$sql2 = "SELECT * FROM photos WHERE eventID = '$ID'";
// $query2 = mysqli_query($connect, $sql2);
$result = $db->prepare($sql2);
$result->execute();
while($photos = $result->fetch(PDO::FETCH_ASSOC)){
$cap = $photos['photoName'];
$source = $photos['photoPath'];
?>
<div class="thumbnail">
<?php //echo $cap; ?>
<img src="<?php echo $source;?>">
<?php echo "Photo uploaded to: "."<b>".$albm."</b>"; ?>
</div>
<?php
}
}

最佳答案

尝试使用:

$result = $result->fetchAll();

关于PHP PDO 仅显示第一个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33840094/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com