【问题标题】:Attaching <a href></a> in GROUP_CONCAT()在 GROUP_CONCAT() 中附加 <a href></a>
【发布时间】:2013-06-02 06:05:00
【问题描述】:

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

谁能帮忙解决这个问题?

【问题讨论】:

    标签: php mysql href concat group-concat


    【解决方案1】:

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

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

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

    【讨论】:

    • 我这样转义了引号。但仍然得到同样的错误:(
    • @Jen 也尝试删除这些引号并将其连接起来 (".$str1.", bug_id, ".$str2.")
    • GROUP_CONCAT(CONCAT(".$str1.", bug_id,".$str2.") separator ',') 尝试过这样。还是一样的错误。
    • 在执行之前请echo $query; 并在此处发布它打印的内容吗?
    【解决方案2】:

    我在您使用 $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 
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-15
      • 1970-01-01
      相关资源
      最近更新 更多