group_concat:在浏览器的新行中显示值 [英] group_concat: have values display in a new line on the browser

查看:89
本文介绍了group_concat:在浏览器的新行中显示值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的查询,我正在使用MYSQL的GROUP_CONCAT()函数:

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`

上面的查询在phpmyadmin界面上运行良好,即返回的值以新行显示,如下所示:

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:

我应该提到我甚至尝试使用 br 标记作为分隔符(GROUP_CONCAT( Features.Description SEPARATOR "<br>" ))

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.

任何帮助将不胜感激

推荐答案

这是您要在PHP中执行的操作,而不是MySQL.这将使它可以在html(浏览器)和非html渲染器(cli)中正确显示.之所以在phpMyAdmin中起作用,是因为它使用 nl2br 来转换新行( c1>)转换为html符(<br>).

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>).

示例:

echo nl2br($row['description'];

您的代码可能有所不同,这只是假设$ row是结果中的一行.

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

这篇关于group_concat:在浏览器的新行中显示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆