Forum Moderators: mack

Message Too Old, No Replies

mysql_query help needed

         

hswaseer

12:20 pm on Feb 3, 2004 (gmt 0)

10+ Year Member



Hi Guys

I need some help to make sql query
My database table contains game_name and player_name
And it looks someting like this -

football - tim
football - jim
volleyball - jow
volleyball - joe

and etc

now i want that my first sql_query should show the game_name and when i click on that link it should show the players name in the game

like if i click on link_football it should list the players in it and when i click on volleyball it should show the list of players in this game.

HS

ukgimp

12:31 pm on Feb 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need a way of linking the two tables

“Game_name”
gm_id (pk)
name

“player_name”
pm_id (pk)
name
gm_id (fk)

Query 1
SELECT * FROM Game_name

Query 2
SELECT * FROM “player_name”
WHERE gm_id = X

X = a url parameter from your first query.

Without knowing exactly hat you are after, this may not be exactly what you want but the principle of linking tables/records by the FK (foreign key) should be evident.

transactiongeek

12:38 pm on Feb 3, 2004 (gmt 0)



<?php
mysql_connect("localhost", "uname", "pword");
@mysql_select_db("db") or die ("Unable to select database");

$game_name=$_REQUEST['gamename']

$result=mysql_query("select player_name from games where game_name='$game_name'");

echo "<h1>Players for game: $game_name</h1><br><ul>";

while(list($player_name))= mysql_fetch_row($result))
{
echo "<li>$player_name\n";
}
?>
</ul>

[example.com...]

Hope I'm not doing someone's homework.