I am trying to build a multi dimentional array of students and their data from my database table using mysqli and php.
I want my array to look something like this
Array #$adult array
(
[626] => Array #student no 626 data
(
[name] => emily,
[age] => 43,
[height] => 156,
)
[627] => #student no 627 data
(
[name] => luke,
[age] => 31,
[height] => 176,
)
)
the number being the members id followed by their data.
So i have tried the following
$sql = "SELECT * FROM pzgym_waitinglist WHERE seen = 0 GROUP BY gym_discipline, school_yr, id";
$result = $db->query($sql);
if ($result->num_rows > 0)
{
#set up array
$adult = array();
while($row = $result->fetch_array())
{
$id = $row["id"];
$name = $row["name"];
$age= $row["age"];
$height = $row['height'];
if($row['gym_discipline'] == "Adult Gymnastics")
{
$adult[$id] = "['name'] => $name, ['age'] => $age, ['height'] => $height";
}
}
}
but this isnt producing the correct results, so im guessing my array building sucks :( here is what i am getting.
Array
(
[626] => ['name'] => Emily, ['age'] => 43, ['height'] => 156
[627] => ['name'] => Luke, ['age'] => 31, ['height'] => 176
)
Could someone help me please to build a successful multi dimentional array from the data im my database
Many Thanks