I am now working on getting a Json response from the data in the following table
By using the following Query :
$sql = "select * from subject where subject_name = 'maths'";
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_array($result))
{
$data = new stdClass();
$subject_name = $row['subject_name'];
$unit = $row['unit'];
$unit_name = $row['unit_name'];
$data->subject_name=$subject_name;
$emparray[] = array('unit' => $unit,
'unit_name' => $unit_name,
);
$data->units=$emparray;
}
echo json_encode(array($data));
I can get the Json response as :
Now what i want was for overall subjects without using where clause (where subject_name = 'maths')
My required Json o/p is as below :


