简体   繁体   English

从Codeigniter中的多个表连接后无法获取数据

[英]Cannot get data after joining from multiple tables in Codeigniter

I want to get data from two tables, the second table is for rating so i want to get rating of products simultaneosly. 我想从两个表中获取数据,第二个表用于评级,因此我想同时获得产品的评级。 Below code is not working for me if i change 如果我更改,下面的代码对我不起作用

$this->db->select('dg_products. ',' , AVG( dg_rating.rating ) As averageRating'); $ this-> db-> select('dg_products。 ',' ,AVG( dg_rating.rating )As averageRating');

to

$this->db->select('*'); $这个 - > DB->选择( '*');

then it is working. 那么它正在工作。 Please help to sort out my issue. 请帮助解决我的问题。

public function get_rating()
    {
        $this->db->select('dg_products.*','*, AVG(`dg_rating.rating`) As averageRating');
        $this->db->from('dg_products');
        $this->db->join('dg_rating', 'dg_products.id = dg_rating.product_id','left');
        $this->db->where('dg_products.is_featured_prod','1');
        $this->db->group_by("dg_products.id");
        $query = $this->db->get();   
        $result = $query->result();
        return $result; 
  }

Try it like this : 像这样尝试:

$this->db->select('dg_products.*, AVG(`dg_rating.rating`) As averageRating');

you just have an unneeded quotes in there. 您只是那里不需要的报价。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM