I am new to php/MySQL, so I apologize in advance for any stupidity on my part. I have a MySQL database for events, and the main table ("Brochure") has multiple Trip Leader fields, e.g., "Leader," "Assistant Leader," "Leader in Training," etc. All of these leader fields get their data from the same "Leaders" table.
So, the data in "Brochure" looks like this:
Trip_Name | Leader | Leader_Asst
-------------------------------------------
Fun Hike | 45 | 29
... and the data in "Leaders" looks like this:
ID | Name
----------------------
45 | Sally Smith
29 | Jane Doe
I am working on a PHP report that will show us all the trips and the leaders. I so far have figured out how to translate one field into the real name, but I am stumped on how to translate more than one field.
Here's what I've got so far:
...
$query = "SELECT Brochure.*, Leaders.Name ".
"FROM Brochure LEFT JOIN Leaders ON Brochure.Leader=Leaders.ID ".
"WHERE Brochure='2010 spring' AND Activity='biking' ".
"ORDER BY Date_Full";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo "<table width=590 cellpadding=0 cellspacing=0 border=0>";
echo "<tr><td colspan=2 class=TableTitlePrint>Leaders</td></tr>";
echo "<tr><td colspan=2> </td></tr>";
$i=0;
while ($i < $num) {
$Trip_Name=mysql_result($result,$i,"Trip_Name");
$Leader=mysql_result($result,$i,"Leader");
$Leader_Asst=mysql_result($result,$i,"Leader_Asst");
$Name=mysql_result($result,$i,"Name");
?>
<tr>
<td class="TableHeaderPrint" valign="top"><div class="TableHeaderPrint" style="text-align: right;">Trip Name</div></td>
<td class="TableBodyPrint" xwidth="300" valign="top"><? echo "$Trip_Name"; ?></td>
</tr>
<tr>
<td class="TableHeaderPrint" valign="top"><div class="TableHeaderPrint" style="text-align: right;">Leader</div></td>
<td class="TableBodyPrint" xwidth="300" valign="top"><? echo "$Name"; ?></td>
</tr>
<tr>
<td class="TableHeaderPrint" valign="top"><div class="TableHeaderPrint" style="text-align: right;">Assistant Leader</div></td>
<td class="TableBodyPrint" xwidth="300" valign="top"><? echo "$Leader_Asst"; ?></td>
</tr>
<?
++$i;
}
echo "</table>";
?>
This successfully translates the Leader field into its "friendly" name. I can't figure out how to translate the Leader_Asst field into the"friendly" name.
Thanks much for any help!