【问题标题】:CodeIgniter - ActiveRecord order_by() being applied to all queries not just the one I wantCodeIgniter - ActiveRecord order_by() 应用于所有查询,而不仅仅是我想要的查询
【发布时间】:2012-02-26 16:51:44
【问题描述】:

可能很简单,但我在文档或搜索中没有任何运气。

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

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

它有效,但是我收到错误,因为 order by 子句正在应用于我的所有其他查询,并且我收到错误,因为我的 age 列并不存在于所有表中。

那么它如何将 $this->db->order_by('age', 'ASC') 限制为仅针对该特定查询?

谢谢。

【问题讨论】:

    标签: php codeigniter activerecord


    【解决方案1】:

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

    【讨论】:

    • 知道这很容易。谢谢。
    【解决方案2】:

    应该是这种格式

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-11
      • 1970-01-01
      • 2019-09-11
      • 2016-10-04
      • 1970-01-01
      • 1970-01-01
      • 2016-09-29
      • 1970-01-01
      相关资源
      最近更新 更多