Good day! My task would seem to be simple, but I can’t come up with a code in any way. There is a mysql table:
category date name1 2014-08-28 name2 2014-08-28 name3 2014-08-27 name3 2014-08-26 name1 2014-08-26 At the output you need to get an array:
array( 2014-08-28 => array(name1,name2), 2014-08-27 => array(name3), 2014-08-26 => array(name3,name1) ); I work in the codeigniter framework, maybe there is a tool in it to solve this problem more easily? Because I had to make two calls from the database, a bunch of cycles and it looks like a Chinese code, very ugly and illiterate, already ashamed to show.
GROUP_CONCAT()function, I will not say more, because I have never used it. > group by function is not really a function> already work with this data in php. but that’s what I’ve got for $ data = array (); foreach ($ results as $ result) {if (! isset ($ data [$ result ['date'])) {$ data [$ result ['date']] = array (); } $ data [$ result ['date']] [] = $ category; } voila, in $ data everything is sorted. - etki