0

Using sql query with group_concat through a while loop, I achieved the result below:

$rows[] = array('name' =>$row['customer'] , 'atw' =>$row['atw_number'] ,
     'dr' =>array(array('drnumber'=>(($row['dr_number'])),)),);

{ "name": "MULTIBUILD CORP", "atw": "7146", "dr": [ { "drnumber": "1608,1610,1611" } ] },

instead, can i have something like:

{ "name": "MULTIBUILD CORP", "atw": "7146", "dr": [ { "drnumber": "1608" }, { "drnumber": "1610" }, { "drnumber": "1611" } ] },

4
  • You will have to create a php script like that. I mean you will have to do it manually using some loops. That wil do it Commented Feb 17, 2016 at 21:01
  • What SQL Database are you using? Commented Feb 17, 2016 at 21:01
  • hey bud, its mysql.. Commented Feb 17, 2016 at 21:04
  • yeah thanks for the info pritesh.. You will have to create a php script like that. I mean you will have to do it manually using some loops. That wil do it – pritesh Commented Feb 17, 2016 at 21:13

1 Answer 1

1

Within your while loop replace your current $rows[] = ... with:

$numbers = [];
foreach (explode(',', $row['dr_number']) as $number)
    $numbers[] = ['dr_number' => $number];

$rows[] = array(
    'name' => $row['customer'],
    'atw' => $row['atw_number'],
    'dr' => $numbers
);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.