Friday 15 June 2012

php - Merge three mysql entries to one entry -


I have 3 or 4 entries with different entries than a person with the same name.

  ABC ---- ---- ----------- A 01 XXX A 02 XYZ A 03 ABC   

How can I merge them by choosing them which is always in a way similar to A in the structure:

  ABCDEF --- --- --- --- --- - 01 02 03 XXX XYZ ABC   

Hope you can help me get it.

alternative solutions

If there is a variable number of entries for different users then use the GROUP_CONCAT function. This is a simple way to create a dynamic number of columns in SQL (some processing in php).

  SELECT A, GROUP_CONCAT (B) B, GROUP_CONCAT (C) C from table group A;   

The result will be: - ABC --- --- --- 01,02,03 XXX, XYZ, ABC

It can be further processed in php code.

No comments:

Post a Comment