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


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

可能很简单,但我在文档或搜索方面运气不佳。

我正试图将order by子句添加到我的一个ActiveRecord查询中,如下所示:

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

它是有效的,但我会出错,因为order by子句正在应用于我的所有其他查询,而我会出错是因为我的age列没有出现在所有表中。

那么,它如何将$this->db->order_by("age","ASC")限制为仅限一个特定查询呢?

谢谢。

您应该在$result = $this->db->get('mytable'); 之前有$this->db->order_by();

它应该是这种格式的

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