在GROUP_CONCAT()中附加<a href=""></a>

时间:2013-06-06 09:33:20

标签: php mysql href concat group-concat

我想使用CONCAT()将字符串附加到GROUP_CONCAT函数。 我尝试了以下方法:

$str1 = "<a href='show_bug.cgi?id ='>";
$str2 = "</a>";
$query = "select count(cbm.bug_id) as count,(select concat(round((count(cbm.bug_id)/(select count(*) from techzilla.category_bug_map cbm,techzilla.bugs b where b.assigned_to =$userId  and cbm.bug_id=b.bug_id) * 100 ),2),'%')) as Percentage ,GROUP_CONCAT(CONCAT('$str1', bug_id,'$str2') separator ',') as BugIds from techzilla.bugs b left join techzilla.category_bug_map cbm on cbm.bug_id = b.bug_id where b.assigned_to = $userId and b.creation_ts >= '$fromDate 00:00:00' and b.creation_ts <= '$toDate 00:00:00' and cbm.os IN ('$opess')";

但是当我打印查询时,我收到以下错误:

select count(cbm.bug_id) as count,(select concat(round((count(cbm.bug_id)/(select count(*) from techzilla.category_bug_map cbm,techzilla.bugs b where b.assigned_to =1078 and cbm.bug_id=b.bug_id) * 100 ),2),'%')) as Percentage ,GROUP_CONCAT(CONCAT('', bug_id,'') separator ',') as BugIds from techzilla.bugs b left join techzilla.category_bug_map cbm on cbm.bug_id = b.bug_id where b.assigned_to = 1078 and b.creation_ts >= '2013-05-01 00:00:00' and b.creation_ts <= '2013-06-06 00:00:00' and cbm.os IN ('Windows')
Bad query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'show_bug.cgi?id ='>', bug_id,'') separator ',') as BugIds from techzilla.bug' at line 1

任何人都可以帮忙解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

由于$str1中的引用,我收到错误,我建议逃避它们

$str1 = "<a href=\'show_bug.cgi?id =\'>";

这应该会阻止查询在您的错误指向

时拆分字符串和>

答案 1 :(得分:0)

我使用了$ str1和$ str2的查询部分并在我的本地机器上尝试而不是使用变量我直接在查询中传递href,如下所示

select GROUP_CONCAT(CONCAT(\"&lt; a href=show_bug.cgi?id=&gt;\",id,\"&lt;/a&gt;\") separator ',') as BugIds 
from table_name 

它在这里工作。希望它适合你。