Page 1 of 1

Multidimensional Array from MySQL Table

Posted: Sun May 11, 2008 11:16 pm
by member321
I currently have a MySQL table that is set up like this:
team_id team player
1 Expos David
1 Expos James
1 Expos Jeremy
2 Pirates Alex
2 Pirates Steve

To pull this table into an array, I have this code:
$result = bb_db_query("SELECT * FROM bb_players");
if ($myrow=mysql_fetch_array($result)) {
do {
$players[] = $myrow["player"];
}while ($myrow=mysql_fetch_array($result));
}

where bb_db_query is basically a function that queries the database and bb_players is the name of the table. However, I want to turn the array into a multidimensional array that makes use of the team IDs and teams as well.

How should I go about modifying my code to make a multidimensional array that includes the team IDs and team names linked together, and has sub-arrays consisting of the player names for each teams? I think I can figure out everything except how to include both the IDs and the team names.

Thanks!