I've a feeling the answer to this will be blindingly obvious, but hope for sympathy for a newbie to php and MySql.
I have a database to keep details of people, their skills, subjects, and media. I have four tables (members, skills, subjects, media) and three linking tables (members_skills, members_subjects, members_media). In the linking tables are just MemberID and the SkillID (or SubjectID or MediumID). Members can have multiple skills, subjects and media.
I want to display a list of members on a web page, and with each member their skills, subjects and media. It is this grouping that is defeating me.
I can do the select for, say, members and their media
$sql = 'SELECT members.FirstName, members.LastName, media.MediumName FROM members LEFT JOIN members_media USING (MemberID)' . ' LEFT JOIN media USING (MediumID)';
and display each name once with their media using a kind of loop
$result = mysql_query($sql,$db);
$lastLastName = '';
while (list ($FirstName, $LastName, $MediumName) = mysql_fetch_row($result))
{
if ($lastLastName !=$LastName){
$display_block .= "<br><br>NAME $FirstName $LastName, MEDIA: ";
$firstMedium = 1;
}
if (!$firstMedium) $display_block .= ", ";
$display_block .= $MediumName;
$firstMedium =0;
$lastLastName = $LastName;
}
(and then start the html and <? echo "$display_block"; ?>)
But I get bogged down when trying to add their subjects and skills as well. Do I need to do multiple queries? A different kind of query? A different kind of loop? Nested loop? Any hints on the right approach would be much appreciated, I have a feeling I am coming at it the wrong way.