I have a table (img1) in mysql, and want to show the data at a php page which Col2 data will be combined if Col1 is same value (like the format of img2).
Question:
To handle the combining process, do it in sql query or in php is better? And how can I do so? Thank you.
Something like that:
SELECT COl1, GROUP_CONCAT(COL2, SEPARATOR ' ') as COL2 FROM Table GROUP BY COl1
select id, group_concat(`Col1` separator ',') as `ColumnName`
from
(
select id, concat(`Col1`, ':',
group_concat(`Col2` separator ',')) as `Col1`
from mytbl
group by id, `Col1`
) tbl
group by id;
You can see it implemented here : Sql Fiddle Demo. Exactly what you need.