0

我想使用 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

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

4

2 回答 2

0

由于您的报价,您收到错误消息$str1,我建议您避开它们

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

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

于 2013-06-06T09:36:47.307 回答
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 

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

于 2013-06-06T11:12:23.853 回答