php - Multiple nested array from MySQL query -
i'm using foreach loops access records in nested array:
while ($row = mysql_fetch_assoc($result)){ $test_groups[$row['group_name']][] = $row['lab_test']; } foreach($test_groups $group_name => $tests){ echo "<tr><td><span class='test_group_name'>" . $group_name . "</span></td></tr>"; foreach($tests $test){ echo "<tr><td>" . $test . "</td></tr>"; } echo "<tr><td> </td></tr>"; } echo '</table>';
this works ok. need add level nested array, like:
$departments[$row['department_name']][$row['group_name']][] = $row['lab_test'];
would work , how should adjust each loops above cater this?
assign array should []
@ end
$departments[$row['department_name']][$row['group_name']][] = $row['lab_test'];
foreach loop be:
foreach ($departments $dep_name => $groups) { echo $dep_name; foreach ($groups $group_name => $tests) { echo $group_name; foreach ($tests $test) { echo $test; } } }
it's echo
es, make there html need.
Comments
Post a Comment