您好请参考我在模型中的以下代码
public function common_report($where) {
$this->db->select('*');
$this->db->from('collect_data_form_history_db as ch');
$this->db->join('board_artwork_history_db as bh','bh.shop_id = ch.shop_id');
$this->db->where('bh.shop_id', $where);
// $this->db->where('bh.shop_id',$where);
$query = $this->db->get();
return $query->result_array();
}
我想要的是来自table_data_form_history_db和board_artwork_history_db的所有数据。 我得到的数据但格式错误。 在表格' collect_data_form_history_db'我有11个条目,在board_artwork_history_db我有18个条目。 所以我得到的数据应该是29行,但我获得198行意味着11 * 18。 请告诉我解决方案
答案 0 :(得分:0)
你需要使用左连接。试试这种方式
$this->db->join('board_artwork_history_db as bh','bh.shop_id = ch.shop_id', 'left');
答案 1 :(得分:0)
$this->db->select('t1.*, t2.*')
->from('collect_data_form_history_db t1, board_artwork_history_db t2')
->where('t1.shop_id = t2.shop_id')
->where('t2.shop_id', $where);
$query = $this->db->get();
答案 2 :(得分:0)
尝试完全外连接
public function common_report($where) {
$this->db->select('*');
$this->db->from('collect_data_form_history_db as ch');
$this->db->join('board_artwork_history_db as bh','bh.shop_id = ch.shop_id', 'full outer');
$this->db->where('bh.shop_id', $where);
// $this->db->where('bh.shop_id',$where);
$query = $this->db->get();
return $query->result_array();
}