Perhaps you will sometimes encounter the need to put the data of a table in the database according to the table of a field category output, such as a data table area as follows
We need to sort out the inside area according to the Serialize field, such as this form:
Areas Serialize
Ah blue, Ai Shayun A
Chongqing Forest, Heritage home C
Red Army Building community, Seaman's Village H
.........
To be shown in this form, you can do so by using the Group_concat in MySQL ()
, GROUP by implementation,
Select Serialize,group_concat (area) as areas from the area group by Serialize;
You can get the data table above
Group_concat (area) Here is the area according to group by serialize the same category (a\b\c) of the data together, separated by commas, such as "Red Army building community, Seamen's Village" ...
So you can sort out the output, and of course you need to split the serialize (explode ()), Traverse (foreach) ...
The above mentioned is the entire content of this article, I hope you can enjoy.