我正在尝试显示已上传到我网站上的所有照片,但我只能显示第一行数据。任何人都可以帮助我。
<?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
}
}
答案 0 :(得分:0)
尝试使用:
$result = $result->fetchAll();