Php 编码点火器->;来自(多个表)

Php 编码点火器->;来自(多个表),php,codeigniter,Php,Codeigniter,大家好:) 我想从两个表中获取数据。我不想要任何特定的“where”选项,因此这是我的模型代码: $this->db->from('table1, table2'); $this->db->order_by('table1.date, table2.date', "desc"); $query = $this->db->get('', $num, $offset); return $query->result_array(); 这样,我只

大家好:) 我想从两个表中获取数据。我不想要任何特定的“where”选项,因此这是我的模型代码:

$this->db->from('table1, table2');      
$this->db->order_by('table1.date, table2.date', "desc");
$query = $this->db->get('', $num, $offset);

return $query->result_array();
这样,我只能从“table2”中获得信息,它只包含一篇文章,而这篇文章在第页上重复了好几次。这两个表具有相同的结构,我希望通过这种方式编写“order_by”会有所帮助,但不会。如果我进行任何其他操作,我只能从一个表中获取信息。按日期订购很重要。 希望任何人都会发现这个问题很有趣,也会有所帮助。提前谢谢

编辑部分: 功能:

$this->db->get("table1");

$comm_numbers = $this->db->count_all_results("table1");

$config['base_url'] = base_url();
$config['total_rows'] = $comm_numbers;
$config['per_page'] = '5';
$config['uri_segment'] = 1;
$this->pagination->initialize($config);

$this->load->model("model_get_all");
$data["results"] = $this->model_get_all->getData1($config['per_page'], $this->uri->segment(1));
$this->load->helper('url');
试试这个:

$this->db->query('SELECT id, title, text, views, date, image FROM table1 UNION SELECT id, title, text, views, date, image FROM tablee2');
更新: 使用CodeIgniter分页进行查询:

$this->db->query("SELECT id, title, text, views, date, image FROM table1 UNION SELECT id, title, text, views, date, image FROM tablee2 LIMIT $offset, $num");
更新2:好的,我只在
$offset
变为
null
时更改位置

$this->db->get("table1");

$comm_numbers = $this->db->count_all_results("table1");

$config['base_url'] = base_url();
$config['total_rows'] = $comm_numbers;
$config['per_page'] = '5';
$config['uri_segment'] = 1;
$this->pagination->initialize($config);

$page = ($this->uri->segment(1)) ? $this->uri->segment(1) : 0;

$this->load->model("model_get_all");
$data["results"] = $this->model_get_all->getData1($config['per_page'], $page);
$this->load->helper('url');

告诉我们Table1和table2的列,如果tableID、title、text、views、date和image的表结构都相同,那么我认为您应该使用它而不是join。我已经处理过这些表,如果我单独处理每个表,我从中检索到了信息。是的,这终于起作用了!谢谢埃尔曼,还有考拉·德夫。很好的方法。但是有没有办法节省$num和$offset用于分页?是的。现在我将更新答案,并添加
$num
$offset
,感谢如此快速的更新,但我得到了错误号:1327未声明变量:$offset。我正在使用默认的CI分页方法try with“”(double')@AlexanderYakovluk