Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Codeigniter查询生成器连接3表_Codeigniter_Model View Controller_Query Builder - Fatal编程技术网

Codeigniter查询生成器连接3表

Codeigniter查询生成器连接3表,codeigniter,model-view-controller,query-builder,Codeigniter,Model View Controller,Query Builder,我需要你的帮助,我有一张这样的桌子 单击id为的按钮查看产品时,我想查看产品的详细信息。 这就是我所做的。。似乎我需要在id和产品之间进行单一报价。。或者codeigniter是否有一个查询生成器来实现这一点 function get_detail_product($id_product){ $query = "SELECT p.id_product, p.product_name, p.price, p.discount, c.category, b.bran

我需要你的帮助,我有一张这样的桌子

单击id为的按钮查看产品时,我想查看产品的详细信息。 这就是我所做的。。似乎我需要在id和产品之间进行单一报价。。或者codeigniter是否有一个查询生成器来实现这一点

function get_detail_product($id_product){
        $query = "SELECT 
        p.id_product, p.product_name, p.price, p.discount, c.category, b.brand_name, p.description, p.spesification, p.picture, p.begin_date, p.end_date, p.qty
        FROM tbl_product as p, tbl_category as c, tbl_brand as b 
        WHERE p.id_Category = c.id_Category and p.id_brand = b.id_brand
        and id_product = ".$id_product;
        return $this->db->query($query);
    }

看起来您没有正确返回它。试试这个。(未测试)


CodeIgniter确实有一个查询绑定器,可以实现类似的功能。我还没有彻底检查过您的SQL,不知道它是否有效,但类似这样的查询看起来像:

$this->db->select('p.id_product, p.product_name, p.price, p.discount, c.category, b.brand_name, p.description, p.spesification, p.picture, p.begin_date, p.end_date, p.qty')
      ->from('tbl_product as p, tbl_category as c, tbl_brand as b')
      ->where('p.id_Category = c.id_Category')
      ->where('p.id_brand = b.id_brand')
      ->where('id_product', $id_product);
      $query = $this->db->get();
      return $query;
$this->db->select('*');
    $this->db->from('tbl_product');
    $this->db->join('tbl_category', 'tbl_category.id_category = tbl_products.id_category');
    $this->db->join('tbl_brand', 'tbl_brand.id_brand = tbl_products.id_brand', 'inner');
    $this->db->where('id_product', $id_product);
    $query = $this->db->get();
    return $query;
我有点不清楚你想要实现什么,我没有完全理解这个问题。您只是想让查询正常工作,还是想寻求建议,以便将所有信息集中到一行中?如果要联接表,可以尝试以下操作:

$this->db->select('p.id_product, p.product_name, p.price, p.discount, c.category, b.brand_name, p.description, p.spesification, p.picture, p.begin_date, p.end_date, p.qty')
      ->from('tbl_product as p, tbl_category as c, tbl_brand as b')
      ->where('p.id_Category = c.id_Category')
      ->where('p.id_brand = b.id_brand')
      ->where('id_product', $id_product);
      $query = $this->db->get();
      return $query;
$this->db->select('*');
    $this->db->from('tbl_product');
    $this->db->join('tbl_category', 'tbl_category.id_category = tbl_products.id_category');
    $this->db->join('tbl_brand', 'tbl_brand.id_brand = tbl_products.id_brand', 'inner');
    $this->db->where('id_product', $id_product);
    $query = $this->db->get();
    return $query;