我有这个查询,它会拉出附加到特定主题公园的游乐设施列表,并显示它们的详细信息和任何附加的照片(照片是从单独的表中提取的,并通过“ride_id”连接)。下面是查询
$park_id = $_GET['park_id'];
$query2="SELECT * FROM `tpf_rides` LEFT JOIN tpf_images
ON tpf_rides.ride_id=tpf_images.ride_id
WHERE tpf_rides.park_id = $park_id AND `type` LIKE '%Roller Coaster%' ORDER BY `name` ASC";
$result2 = $pdo->query($query2);
问题是当我列出从此查询中提取的结果时,它会创建重复的行以供骑行,每个图像一个。
想要的是:
Ride 1 - Type <br>
Manufactured by xxx, Opened xxxx <br>
image1 image2
Ride 2 - Type <br>
Manufactured by xxx, Opened xxxx <br>
image1 image2 image3
但我目前拥有的是
Ride 1 - Type <br>
Manufactured by xxx, Opened xxxx <br>
image1
Ride 1 - Type <br>
Manufactured by xxx, Opened xxxx <br>
image2
Ride 2 - Type <br>
Manufactured by xxx, Opened xxxx <br>
image1
下面是我正在使用的每个循环。我需要对查询或循环进行哪些更改才能使其正常工作?
<?php foreach ($result2 as $row2): ?>
<h2 style="display:inline;"><?php echo $row2['name']; ?></h2><h3 style="display:inline;"> - <?php echo $row2['type']; ?></h3>
<h3>Manufactured by <?php echo $row2['make']; ?>, Opened <?php echo $row2['opened']; ?> </h3>
<img border="0" src="<?php echo $row2['url']; ?>" style="max-height:250px; max-width:250px;" >
<br>
<?php endforeach; ?>
我仍处于了解 PHP 和 MySQL 的早期阶段,因此详细的答案将非常有帮助。谢谢你。