首页 > 解决方案 > 如何在codeigniter中联合查询?

问题描述

我尝试使用这个

$this->db->select('title, content, date');
$this->db->from('mytable');
$query = $this->db->get();
$subQuery1 = $this->db->_compile_select();

$this->db->_reset_select();
$this->db->select('title, content, date');
$this->db->from('mytable2');
$query = $this->db->get();
$subQuery2 = $this->db->_compile_select();

$this->db->_reset_select();
$sql = ("$subQuery1 UNION $subQuery2");

$rowsdata = $this->db->query($sql)->result_array();
print_r($rowsdata);
die();

当我使用 print_r(); 查看数组结果,但什么也没发生。

标签: mysqlcodeigniter

解决方案


推荐阅读