Just need help with a query so I can display the results correctly
Im trying to join information from three separate tables so they can be displayed correctly on one page.
Currently i have this:
Where it displays the information from two tables correctly
Here is how my tables are setup:
table console
sysId | system
1|pc
2|playstation
3|SNES
table employee
id|employee
1|None
2|Greg
3|Joe
4|Jane
table genre
genreId|genre
1|action
2|adventure
3|sports
table games
gameId|title|snumber|genreId|date|sysId|id
1|tony hawk|abc123|3|2000|2|3
So I want to display the information from the Games table but since genreId, sysId, and id are pulling information from the other three tables, I need to have the name of the genre, the name of the system and the name of the employee who has the game instead of their respective numbers.
I got it to show the GENRE instead of the id, but I can't figure out how to show the names for the rest.
The HTML produced:
How do i get the query to reflect the need to show the names instead of their numbers? I dont know when to use LEFT JOIN or if its necessary.
Im trying to join information from three separate tables so they can be displayed correctly on one page.
Currently i have this:
Code:
$q = "SELECT
genre.genre,
games.*
FROM genre,games
WHERE genre.genreId=games.genreId
ORDER BY title";
Where it displays the information from two tables correctly
Here is how my tables are setup:
table console
sysId | system
1|pc
2|playstation
3|SNES
table employee
id|employee
1|None
2|Greg
3|Joe
4|Jane
table genre
genreId|genre
1|action
2|adventure
3|sports
table games
gameId|title|snumber|genreId|date|sysId|id
1|tony hawk|abc123|3|2000|2|3
So I want to display the information from the Games table but since genreId, sysId, and id are pulling information from the other three tables, I need to have the name of the genre, the name of the system and the name of the employee who has the game instead of their respective numbers.
I got it to show the GENRE instead of the id, but I can't figure out how to show the names for the rest.
The HTML produced:
Code:
<table>
<tr>
<td width="27%"><b><font face="Arial, Helvetica, sans-serif">Game</font></b></td>
<td width="13%"><b><font face="Arial, Helvetica, sans-serif">Serial Number</font></b></td>
<td width="17%"><b><font face="Arial, Helvetica, sans-serif">Genre</font></b></td>
<td width="13%"><b><font face="Arial, Helvetica, sans-serif">Date Published</font></b></td>
<td width="17%"><b><font face="Arial, Helvetica, sans-serif">System / Console</font></b></td>
<td width="13%"><b><font face="Arial, Helvetica, sans-serif">On Loan To</font></b></td>
</tr>
<?php
while($myrow = mysql_fetch_array($result)) {
echo " <tr>
<td><font face=\"Arial, Helvetica, sans-serif\" size=2>".$myrow["title"]."</font></td>
<td><font face=\"Arial, Helvetica, sans-serif\" size=2>".$myrow["snumber"]."</font></td>
<td><font face=\"Arial, Helvetica, sans-serif\" size=2>".$myrow["genre"]."</font></td>
<td><font face=\"Arial, Helvetica, sans-serif\" size=2>".$myrow["date"]."</font></td>
<td><font face=\"Arial, Helvetica, sans-serif\" size=2>".$myrow["system"]."</font></td>
<td><font face=\"Arial, Helvetica, sans-serif\" size=2>".$myrow["employee"]."</font></td>
</tr>\n";
}
?>
</table>
How do i get the query to reflect the need to show the names instead of their numbers? I dont know when to use LEFT JOIN or if its necessary.
Code:
$q = "SELECT
genre.genre,
games.*
FROM genre,games
WHERE genre.genreId=games.genreId
ORDER BY title";