-1

I have the following dataset:

ToDo_Name      List_ID
-------------------------------
Read book          1
Study English      2
Do excercises      2
Sleep              1
Eat                1

I need to group this data by List_ID creating the array like this (and send it as json to frontend):

$result = array(
      array("listId" => 1, array('Read book', 'Sleep', 'Eat ')),
      array("listId" => 2, array('Study English', 'Do excercises'))
);

I can't understand - should I do this using some SQL query or PHP array methods? Will be happy to hear any advices...

missbells
  • 53
  • 8

1 Answers1

0

You could use group concat ..

  select list_id, group_concat(ToDo_Name)
  from mytable 
  group by  list_id
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107