【问题标题】:codeigniter inner join not working as expectedcodeigniter 内部连接没有按预期工作
【发布时间】:2016-03-15 15:47:22
【问题描述】:

我有一个如下内连接查询,

SELECT * FROM shop_offer so INNER JOIN shop s ON s.shop_id = so.shop_id INNER JOIN city c ON c.city_id = s.city_id INNER JOIN locality l ON l.locality_id = s.locality_id INNER JOIN category ca ON ca.category_id = s.category_id WHERE so.offer_discount >= 10 AND so.publish = 1

在 phpmyadmin 中执行上述查询时,结果如预期只显示一行。

但是当我在 codeigniter 中尝试这个查询时,结果显示 3 行。我的codeigniter代码是,

        $this->db->select('*');
        $this->db->from('shop_offer as so');
        $this->db->join('shop as s', 's.shop_id = so.shop_id');
        $this->db->join('city as c', 'c.city_id = s.city_id');
        $this->db->join('locality as l', 'l.locality_id = s.locality_id');
        $this->db->join('category as ca', 'ca.category_id = s.category_id');
        $this->db->where(array('so.offer_discount >=' => 10, 'so.publish' => 1));
        $query = $this->db->get();

codeigniter 代码有什么问题。我是codeigniter的新手。有什么办法可以解决这个错误。

【问题讨论】:

    标签: php mysql codeigniter join


    【解决方案1】:

    您也可以尝试像这样运行查询,

    $this->db->query("SELECT * FROM shop_offer so 
        INNER JOIN shop s ON s.shop_id = so.shop_id 
        INNER JOIN city c ON c.city_id = s.city_id 
        INNER JOIN locality l ON l.locality_id = s.locality_id 
        INNER JOIN category ca ON ca.category_id = s.category_id 
        WHERE so.offer_discount >= 10 AND so.publish = 1");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-28
      • 2016-12-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多