Forum Moderators: coopster

Message Too Old, No Replies

multiple queries into one recurring php table

         

theref

6:32 am on Jul 16, 2007 (gmt 0)

10+ Year Member



Hi

I have a database which records details of Official appointments to soccer games. I want to be able to show all games in the database along with the Officials that have been appointed to the games.

My question is, how do I get values from 4 seperate queries to show in one recurring php table?

When all the data is shown together I would like the following to be displayed:

game_id, team_1, team_2, venue, date, competition, referee, asst1, asst2, 4th official - then this row repeats for each game.

Any help is much appreciated as I am totally stuck here.

My DB is organised with the following tables:

official: game_id, official_type, ref_id
official_type: name_id, name
referee: ref_id, name
games: game_id, team_1, team_2, venue, date, competition

The links between the tables are:

games.game_id - official.game_id
official.official_type - official_type.name_id
official.ref_id - referee.ref_id

I extract all the data from the games table with

$sql = mysql_query("select game_id, team_1, team_2, date, venue, competition from ref_games") or die(mysql_error());

I get which referee is associated with that game with

$sql2 = mysql_query("SELECT ref_referee.name FROM ((ref_games INNER JOIN ref_official ON ref_games.game_id=ref_official.game_id) INNER JOIN ref_officialtype ON ref_official.official_type=ref_officialtype.name_id) INNER JOIN ref_referee ON ref_official.ref_id=ref_referee.ref_id WHERE (((ref_games.game_id)='$game_id') And ((ref_games.game_id)=ref_official.game_id) And ((ref_referee.ref_id)=ref_official.ref_id)) AND ((ref_official.official_type)='1'))");

(I use the same code to get the other 3 officials)

Habtom

7:52 am on Jul 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$sql = mysql_query("SELECT G.game_id, G.team_1, G.team_2, G.date, G.venue, G.competition, OT.name, R.name from ref_games G, official_type OT, referee R
WHERE G.game_id = O.game_id AND O.official_type = OT.name_id AND O.ref_id = R.ref_id") or die(mysql_error());

Something like the above. You can convert it to INNER joins.

If I misunderstood you, let me know.