I currently have this query
try
{
$park_id = $_GET['park_id'];
$query3="SELECT * FROM `tpf_rides` WHERE `park_id` = $park_id ORDER BY `name` ASC";
$result3 = $pdo->query($query3);
}
catch (PDOException $e)
{
$output = 'Unable to pull rides.';
include 'output.html.php';
}
the results of which are displayed here
<?php foreach ($result3 as $row3): ?>
<h2 style="display:inline;"><?php echo $row3['name']; ?></h2><h3 style="display:inline;"> - <?php echo $row3['type']; ?></h3>
<h3>Manufactured by <?php echo $row3['make']; ?>, Opened <?php echo $row3['opened']; ?> </h3>
<br>
<?php endforeach; ?>
My problem is this. I have multiple photos of each ride, the URLs of which are stored in the table tpf_images. The connecting column is ride_id, found in both tpf_rides and tpf_images. How do I run a query so that during the above foreach loop it will also pull all connected image URLs for each ride that can then be displayed as part of the loop?
Please be as clear as possible I am still learning PHP! Thank you.
Checkout LEFT JOIN for mysql.
So your query would look something like this:
SELECT *
FROM tpf_rides
LEFT JOIN tpf_images
ON tpf_rides.ride_id=tpf_images.ride_id
WHERE park_id = $park_id
ORDER BY `name` ASC