Here\'s my table structure.
I\'m trying to convert MySQL to nested JSON, but am having trouble figuring out how to build the multidimensional array in PHP.
T
Change your while to this:
while ($row = mysqli_fetch_assoc($fetch)) {
$row_array[$row['school_name']]['school_name'] = $row['school_name'];
$row_array[$row['school_name']]['terms']['term_name'] = $row['term_name'];
$row_array[$row['school_name']]['terms']['department_name'][] = array(
'department_name' => $row['department_name'],
'department_code' => $row['department_code']
);
}
If you want to achieve result like the example, maybe you should consider using this method:
Probably it's not an effective program, but it should gives you best result. Hope it helps :)