简体   繁体   English

Codeigniter如何通过此查询排序

[英]Codeigniter how to order by this query

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

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

try this format, just as an example 尝试这种格式,仅作为示例

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

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

you will get good idea about codeignitor databse conceepts 您将对Codeignitor Databse概念有个好主意

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

For more information go to codeigniter documentation 有关更多信息,请转到codeigniter 文档。

First, you're using the get() method terribly wrong. 首先,您使用的get()方法非常错误。 Where you got that syntax, I have no idea. 哪里有这种语法,我都不知道。

Since get() is a method that triggers the query, all parameter methods that add your query's details - like where() , order_by() , etc. - should come before it. 由于get()是触发查询的方法,因此添加查询详细信息的所有参数方法where()例如where()order_by()等)都应位于该方法之前

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

I'd also recommend using a JOIN instead of selecting two tables with a weird WHERE sequence. 我还建议使用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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM