group_concat: have values display in a new line on the browser

Deadly 提交于 2019-12-24 11:27:07

问题


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:

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:

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:


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.



来源:https://stackoverflow.com/questions/32701156/group-concat-have-values-display-in-a-new-line-on-the-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!