2013-03-29 30 views
0

订购这是我的查询在那里我只显示9行,但whow按日期 如何和订购,我应该(在当前查询的顺序)加我笨如何通过这个查询

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

回答

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(); 

欲了解更多信息,请访问笨documentation

+0

这工作得很好,我感谢你的帮助 我怎么能设置条件,例如活动= 1 – rafiq

+0

$ this-> db->其中('active',1); – tuffkid

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(); 
+0

*但在这里我不知道如何设置的行只显示9它显示了我所有的行* – rafiq

+0

看到更新的答案 –

+0

感谢这工作得很好 – rafiq

0

首先,您使用的get() method可怕的错误。你有什么语法,我不知道。

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

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

我还建议使用连接而不是选择两个表与奇怪的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(); 
+0

它工作我欣赏 – rafiq

+0

请检查答案作为解决方案,如果它为你工作。 –