CodeIgniter GROUP_CONCAT和join [英] CodeIgniter GROUP_CONCAT and join

查看:451
本文介绍了CodeIgniter GROUP_CONCAT和join的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图想办法将这两个表连接在一起,这是我能做的,但如果它找到多个匹配的值,它再次显示了产品表中的所有内容。现在我试图使用MySQL group_concat在一起列出所有的tName在数组中的一个字段,但我不断得到MySQL的错误:

I am trying to figure a way to join these two tables together, which I was able to do, but if it found more than one value that matched, it showed everything from the product table again. Now I am trying to use the MySQL group_concat together to be able to list all of tName in one field in the array but I keep getting an error with MySQL:


错误号码:1064

Error Number: 1064

您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以获取在'FROM( sp_product )附近使用的正确语法LEFT OUTER JOIN sp_product_type ON sp_product_type 。第2行的`tCat'

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'

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(); 

任何想法我做错了什么?

Any ideas what I am doing wrong?

推荐答案

似乎有不当的报价的问题。

Seems problem with improper quotes.

应该 GROUP_CONCAT(product_type.tName SEPARATOR,)

尝试以下操作:

$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(); 

这篇关于CodeIgniter GROUP_CONCAT和join的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆