I'm trying to combine a few queries together to (obviously) require my script to make fewer queries.
This will need to combine stuff from three tables. I can handle two, but this is a bit beyond me.
This site will allow users to subscribe to various sports games. When they pull up a page, I want it to show some games (based on other criteria). For each game, it needs to translate the team IDs into their names, but also needs to see if there is an entry for that game subscription already in the database. The result would look something like:
Detroit vs. Atlanta - Subscribe now
Philly vs. LA - Already subscribed
NY vs. Chicago - Subscribe now
etc.
I've removed many of the unnecessary fields from the tables. Here is what we've got:
-----
games
-----
ID
teamone (int)
teamtwo (int)
------
teams
------
ID
teamname (text)
------------
subscriptions
------------
ID
userid
gameid
For the two-part query (turning team IDs into names), I'm using this:
Any thoughts on how this could be done without running a separate query as each row is spit out?Code:$result = mysql_query(" SELECT gms.teamone as teamone, tms.teamname as teamonename, tms2.teamname as teamtwoname, gms.teamtwo as teamtwo FROM games gms, teams tms, teams tms2 WHERE gms.teamone = tms.ID AND gms.teamtwo = tms2.ID");




)

Bookmarks