Forum Moderators: coopster
name_1,
name_2,
name_3,
...
In the second table their are photos related to each name. Some names have multiple photos, some names have none. The correct photo for each name will be marked as "selected". So for example,
SELECT photo_name FROM $table2 WHERE name = 'name_1' AND photo = 'selected'
What I want to do is create a page listing 50 names and each name will have the selected picture next to it if it exists, but the only way I know how to approach this would be to run a query on table 1 once and 50 queries on table 2.
$result = mysql_query( "SELECT name FROM $table1" );
while( $row = mysql_fetch_array( $result ) ) {$query = "SELECT photo_name FROM $table2 WHERE name = 'name_1' AND photo = 'selected'";
...}
This seems highly inneficient and I know their has to be a better way to approach this. Any help or links to a good tutorial would be much appreciated.