I am a newbie to MySQL and I'm trying to learn how to do this right.
I have two tables, one for artist info and another for pictures.
Here are the contents for the 10spot_artists table: artist_id, artist_name, add_date, headline, bio
Here are the contents for the 10spot_pictures table: picture_id, artist_id, path
I want to select all of the pictures from the 10spot_pictures table and print those on a page using php. Underneath each picture I want the artists name to appear. The artists names are retrieved from the 10spot_artists table where the artist_id from both tables match.
I have tried the following code without much luck. I pieced it together using a book and this forum.
Could anyone help send me in the right direction?
Thanks in advance!
<?php
$sql = "SELECT p.picture_id, p.artist_id, p.location, a.artist_name FROM 10spot_pictures p
INNER JOIN 10spot_artists a
ON a.artist_id = p.artist_id
ORDER BY a.artist_name ASC";
$rows = $db->getAll($sql);
foreach ($rows as $row) {
print "<tr><td><img src=\"$row[p.location]\" /></td></tr>
<tr><td>$row[a.artist_name]</td></tr>
<tr><td> </td></tr>";
}
?>