Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return group_concat data as array

Tags:

php

mysql

I want to return values I retrieve from the db using group_concat as an array of data. Is it possible to do this in the mysql query? Or do I need to explode the data into an array?

GROUP_CONCAT(sh.hold_id) as holds

returns this

[holds] => 3,4

I want it to return:

[holds] => array(3,4)
like image 203
Brad Avatar asked Jul 31 '12 16:07

Brad


2 Answers

As I said in my comment: you need to explode the data into an array, using php code like this:

$holds = explode(',', $holds);

because mysql has no concept of array-type for data.

like image 186
Matteo Tassinari Avatar answered Oct 09 '22 09:10

Matteo Tassinari


MySQL has no concept of arrays. Therefore it is not able to return an array. It is up to your processing code (here the php scripts) to convert the concatenated notation into a php array.

like image 31
arkascha Avatar answered Oct 09 '22 09:10

arkascha