I have this query which pulls a list of rides attached to a particular theme park and shows their details and any attached photos (the photos are pulled from a separate table and connected by 'ride_id'). Below is the query
$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);
The problem is when I list the results pulled from this query it creates duplicate rows for a ride, one for each image.
What is want is:
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
but what I currently have is
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
Below is the for each loop I'm using. What would I need to alter on the query or loop to have this work correctly?
<?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; ?>
I'm still at the early stages of understanding PHP and MySQL so a detailed answer would really help. Thank you.