We have DB type:

id name type 1 first type1 2 first type2 3 second type1 

Request to DB

 $qr = mysql_query("SELECT * FROM `base` GROUP by `name`") or die(mysql_error()); 

After grouping, you must display the data in the following way:

 while($data = mysql_fetch_array($qr)){ echo'Имя: '.$data[name].''; echo'Тип:'.$data[type].''; } 

in the type string, you must list all variants of the type string from mysql, where the name string is the same, but since I was grouped to give only one result, and how to display all?

  • As an option - do not make a request with group by , but just in php process the array as you need (grouped by name, for example), and output. - Moonvvell
  • a bit long, I think there are options to beat through group - f1amestar

1 answer 1

SELECT GROUP_CONCAT (type) types, name FROM base GROUP BY name

The types column stores a string that contains all types separated by a comma by the given name.