codeigniter-sql连接

lskq00tm  于 2021-06-21  发布在  Mysql
关注(0)|答案(3)|浏览(209)

我有两张table:
表1:发货清单=id,发货日期,客户id
表2:发货清单费率-id、发货清单id、物料id、重量、费率
我正试图从 dispatch_lists_rates 对应于 dispatch_lists.date_of_dispatch >= $start_date 以及 dispatch_lists.date_of_dispatch <= $end_date (基本上,我是想得到一个月内售出商品的清单,以及它们的价格)
这是我的密码:

$this->db->select('dispatch_lists_rates.*, dispatch_lists.customer_id, dispatch_lists.date_of_dispatch')
 ->from('dispatch_lists_rates')                 
 ->where('dispatch_lists.date_of_dispatch >= '.$start_date)             
 ->where('dispatch_lists.date_of_dispatch <= '.$end_date)           
 ->join('dispatch_lists', 'dispatch_lists_rates.dispatch_list_id = dispatch_lists.id');

这好像不管用!任何帮助都将不胜感激。提前感谢您的时间!
[编辑]我刚意识到我的代码错了:

->where('dispatch_lists.date_of_dispatch >= '.$start_date)  
should have been  
     ->where('dispatch_lists.date_of_dispatch >= ', $start_date)

谢谢你的帮助!
非常感谢!

vawmfj5a

vawmfj5a1#

->where('dispatch_lists.date_of_dispatch >= '.$start_date)

应该是

->where('dispatch_lists.date_of_dispatch >= ', $start_date)
41ik7eoe

41ik7eoe2#

你必须加上 where 之后的条件 joins 请参考以下代码

$result = $this->db->select('dispatch_lists_rates.*, dispatch_lists.customer_id, dispatch_lists.date_of_dispatch')
 ->from('dispatch_lists_rates')
 ->join('dispatch_lists', 'dispatch_lists_rates.dispatch_list_id = dispatch_lists.id');       
 ->where('dispatch_lists.date_of_dispatch >= ', $start_date)             
 ->where('dispatch_lists.date_of_dispatch <= ', $end_date)
 ->get();

希望这能对你有所帮助。

3okqufwl

3okqufwl3#

试用代码:

$this->db->select('dispatch_lists_rates.*, dispatch_lists.customer_id, 
                    dispatch_lists.date_of_dispatch');

$this->db->from('dispatch_lists_rates');

$this->db->join('dispatch_lists', 'dispatch_lists_rates.dispatch_list_id = 
                dispatch_lists.id');

$this->db->where(array('dispatch_lists.date_of_dispatch' >= $start_date, 
                        'dispatch_lists.date_of_dispatch' <= $end_date));

$query = $this->db->get();

相关问题