【发布时间】:2013-03-11 07:42:22
【问题描述】:
我正在尝试这个
$this->db->join('tableTwo as b','','CROSS');
$result = $this->db->get('tableOne as a')->result();
一些解决方案?
【问题讨论】:
-
加入选项有:左、右、外、内、左外、右外。
标签: php codeigniter activerecord
我正在尝试这个
$this->db->join('tableTwo as b','','CROSS');
$result = $this->db->get('tableOne as a')->result();
一些解决方案?
【问题讨论】:
标签: php codeigniter activerecord
对于那些前来查看 Codeigniter 4 答案的人:
// tableOne is defined in the model
$this->model->join('tableTwo', 'column_x= column_y', 'cross');
第一个参数是表名,下一个参数是连接条件,第三个参数是连接类型。
所以如果你有这样的SQL语句:
cross join producto_resumen_color on prre_id = prco_prre_id
你会这样做:
->join('producto_resumen_color','prre_id = prco_prre_id', 'cross')
您可以在 CI 的用户指南中找到更多信息。
https://codeigniter.com/user_guide/database/query_builder.html?highlight=join#join
join($table, $cond[, $type = ''[, $escape = NULL]])
Parameters:
$table (string) – Table name to join
$cond (string) – The JOIN ON condition
$type (string) – The JOIN type
$escape (bool) – Whether to escape values and identifiers
【讨论】:
$this->db->join('tableTwo as b','1=1'); //true relation
$result = $this->db->get('tableOne as a')->result();
$result = $this->db->get(['tableOne as a','tableTwo as b'])->result();
$result = $this->db->from(['tableOne as a','tableTwo as b'])
get()->result(); //by this method you can add as many table you want to join
或者通过在 from 中传递一个表,在 get 方法中传递另一个表
$result = $this->db->from('tableOne as a')
get('tableTwo as b')->result();
【讨论】:
你应该这样使用它:
$this->db->join('tableTwo as b','true');
$result = $this->db->get('tableOne as a')->result();
【讨论】:
codeigniter 中交叉连接的解决方案:
$this->db->join('tableTwo as b','true');
$result = $this->db->get('tableOne as a')->result();
【讨论】: