You may sometimes encounter the need to classify the data of a table in a database according to a field in that table, such as a data table area as follows
We need to sort out the area in the Serialize field, for example, in this form:
Areas Serialize
Ah blue, Ai Shayun A
Chongqing Forest, Heritage home C
Red House community, Seaman's Village H
.........
To be shown in this form, you can do this by using the Group_concat () in MySQL
, GROUP by implementation,
Select Serialize,group_concat (area) as areas from area group by Serialize;
You can get the data sheet above
The Group_concat (area) Here is based on the group by serialize the same category (a\b\c) data, separated by commas, such as "Red House community, Seamen's Village" ...
So you can sort the output, and of course you need to split the serialize (explode ()), Traverse (foreach) ...
How MySQL accesses a data table to sort output by a field