0

这是我的查询,我只显示 9 行,但是按日期排序我应该如何以及在哪里添加我的(在当前查询中排序)

$q = $this->db->get('exchange_rate, country', 9,'exchange_rate.CountryId = country.CountryId');
4

4 回答 4

0

试试这种格式,作为一个例子

         $this->db->select('a.exchange_rate, b.country');
         $this->db->from('exchange_rate a');
         $this->db->join('country b','b.CountryId = a.CountryId');
         $this->db->order_by("yourOrderByColumn",'DESC');
         $this->db->limit(9);
         $query = $this->db->get();
于 2013-03-29T07:33:45.777 回答
0

http://ellislab.com/codeigniter/user-guide/database/active_record.html

您将对 codeignitor 数据库概念有很好的了解

于 2013-03-29T07:34:32.820 回答
0
$this->db->from('exchange_rate');
$this->db->join('country', 'exchange_rate.CountryId = country.CountryId');
$this->db->limit(9);
$this->db->order_by("date", "asc");
$query = $this->db->get();

有关更多信息,请转到 codeigniter文档

于 2013-03-29T07:36:53.920 回答
0

首先,您使用的get()方法非常错误。你从哪里得到这种语法,我不知道。

由于get()是触发查询的方法,所有添加查询详细信息的参数方法(如where()order_by()等)都应该它之前。

$this->db->order_by('column', 'ASC');
$this->db->get('table_name');

我还建议使用 JOIN 而不是选择具有奇怪WHERE序列的两个表。

$this->db->select('column, another_column, etc');
$this->db->from('table');
$this->db->join('another_table', 'another_table.column = table.column');
$this->db->order_by('sort', 'DESC');
$query = $this->db->get();
于 2013-03-29T07:38:30.507 回答