group_concat: have values display in a new line on

2019-08-04 21:48发布

I have a simple query that i'm using MYSQL'S GROUP_CONCAT() function:

SELECT `ProductID` , GROUP_CONCAT( Description
SEPARATOR "\n" ) AS description
FROM Features
GROUP BY `ProductID`

The above query works fine on the phpmyadmin interface i.e. the values are returned displayed in a new line as shown below:

enter image description here

However, when i run the query in the browser, the values are separated by a space and not in a new line as i would wish:

enter image description here

i should mention i have even tried using the br tags as the separator (GROUP_CONCAT( Features.Description SEPARATOR "<br>" ))

but still doesn't display the values in a new line.

Any help will be highly appreciated

1条回答
看我几分像从前
2楼-- · 2019-08-04 22:26

This would be something you want to do in PHP not MySQL. This will allow for it to display properly for both html (browser) and non html renderers (cli). The reason this works in phpMyAdmin is because it uses nl2br to convert new lines (\n) to html breaks (<br>).

Example:

echo nl2br($row['description'];

Your code may be different this is just assuming $row is a single row from the results.

查看更多
登录 后发表回答