2013-06-06 45 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 

它在這裏工作。希望對你有效。