2013-06-06 49 views
0

我想使用CONCAT()将字符串附加到GROUP_CONCAT函数。 我试过如下:在GROUP_CONCAT()中附加<a href></a>()

$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 

谁能请在解决这个帮助?

回答

0

你在你的$str1获得,因为引用的错误,我建议逃脱他们

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

这应该防止查询拆分字符串,并>为你的错误指向

+0

我逃脱了这样的引号。但仍然得到相同的错误:( –

+0

@Jen尝试删除这些引用太多并连接它(“。$ str1。”,bug_id,“。$ str2。”) – Fabio

+0

GROUP_CONCAT CONCAT(“。$ str1。”,bug_id,“。$ str2。”)separator',') 尝试过那样,仍然是同样的错误 –

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 

它在这里工作。希望对你有效。