简体   繁体   English

CodeIgniter - ActiveRecord order_by()应用于所有查询,而不仅仅是我想要的查询

[英]CodeIgniter - ActiveRecord order_by() being applied to all queries not just the one I want

Probably quite a simple one, but I'm not having any luck in the docs or searches. 可能很简单,但我在文档或搜索中没有运气。

I'm trying to add an order by clause to just one of my ActiveRecord queries as follows: 我正在尝试将order by子句添加到我的一个ActiveRecord查询中,如下所示:

$result = $this->db->get('mytable');
$this->db->order_by('age', 'ASC');

It works, however I get errors because the order by clause is being applied to all my other queries and I get errors because my age column is not present in all tables. 它工作,但我得到错误,因为order by子句被应用于我所有其他查询,我得到错误,因为我的年龄列不存在于所有表中。

So how do it limit $this->db->order_by('age', 'ASC') to just that one specific query? 那么如何将$ this-> db-> order_by('age','ASC')限制为只有一个特定的查询?

Thanks. 谢谢。

You should have $this->db->order_by(); 你应该有$this->db->order_by(); before $result = $this->db->get('mytable'); $result = $this->db->get('mytable');

It should be in this format 它应该采用这种格式

$this->db->where("tablename.column", $task_id);
$this->db->order_by('tablename.column', 'ASC'); // or 'DESC'
$this->db->from('table');

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

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