加入收藏 | 设为首页 | 会员中心 | 我要投稿 核心网 (https://www.hxwgxz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程 > 正文

php – CodeIgniter GROUP_CONCAT并加入

发布时间:2021-05-23 01:36:56 所属栏目:编程 来源:网络整理
导读:我试图找到一种方法将这两个表连接在一起,我能够做到,但如果找到多个匹配的值,它会再次显示产品表中的所有内容.现在我试图将MySQL group_concat一起使用,以便能够在数组中的一个字段中列出所有tName但是我一直在使用MySQL收到错误: Error Number: 1064 You

我试图找到一种方法将这两个表连接在一起,我能够做到,但如果找到多个匹配的值,它会再次显示产品表中的所有内容.现在我试图将MySQL group_concat一起使用,以便能够在数组中的一个字段中列出所有tName但是我一直在使用MySQL收到错误:

Error Number: 1064

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 ‘FROM (sp_product) LEFT OUTER JOIN sp_product_type ON sp_product_type.`tCat’ at line 2

SELECT sp_product.name,sp_product.price,sp_product.perm_name,sp_product.description,GROUP_CONCAT(product_type.tName SEPARATOR FROM (sp_product) LEFT OUTER JOIN sp_product_type ON sp_product_type.tCategory = sp_product.type WHERE perm_name = ‘bacon’

$this->db->select('product.name,product.price,product.perm_name,product.description,GROUP_CONCAT(product_type.tName SEPARATOR ',') as product_type.tName'); 
$this->db->from('product');
$this->db->where('perm_name',$this->uri->segment(2));
$this->db->join('product_type','product_type.tCategory = product.type','LEFT OUTER');
$query = $this->db->get(); 

我有什么想法我做错了吗? 最佳答案 似乎报价不当引起问题.

它应该是GROUP_CONCAT(product_type.tName SEPARATOR“,”)

试试以下:

$this->db->select('product.name,GROUP_CONCAT(product_type.tName SEPARATOR ",") as product_type.tName'); 
    $this->db->from('product');
    $this->db->where('perm_name',$this->uri->segment(2));
    $this->db->join('product_type','LEFT OUTER');
    $query = $this->db->get(); 

(编辑:核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读