1

Extracting Values from Nested JSON Data !

$response = array();
$result = mysqli_query($conn, "
    SELECT id, GROUP_CONCAT(CONCAT_WS(':', Name) SEPARATOR ',') AS Result 
    FROM mytbl GROUP BY id
");
mysqli_num_rows($result);
if(mysqli_num_rows($result) > 0){
    while($row = mysqli_fetch_assoc($result)){
        $char = array("id"=>$row["id"], "char"=>[$row["Result"]]);
        array_push($response,array('Attr'=>$char));
    }
}
echo json_encode($response);

i added photo for what i need

Nested Json Data

Paul Spiegel
  • 30,925
  • 5
  • 44
  • 53

1 Answers1

0

Just Explode it with PHP

$response = array();
$result =mysqli_query($conn, "

SELECT id, GROUP_CONCAT(CONCAT_WS(':', Name) SEPARATOR ',') AS Result 
FROM mytbl GROUP BY id ");
mysqli_num_rows($result);

if(mysqli_num_rows($result) > 0){
  while($row = mysqli_fetch_assoc($result)){
    $char = array("id"=>$row["id"],"char"=>explode(',', $row["Result"]));
    array_push($response,array('Attr'=>$char));
  }
}
Malkhazi Dartsmelidze
  • 4,783
  • 4
  • 16
  • 40