繁体   English   中英

Codeigniter和活动记录排序数据库结果

[英]codeigniter and active record ordering db result

$pag = $this->db->get('articles', $config['per_page'], $this->uri->segment(4));         
$data['records'] = $pag->result();

我已经尝试过

$pag = $this->db->get('articles', $config['per_page'], $this->uri->segment(4));         
$this->db->order_by('published', 'ASC');
$data['records'] = $pag->result();

使用ASCdesc我都看不到任何变化。

我在这里做错什么了吗?

谢谢

尝试这个。 将order_by语句移到顶部。

$this->db->order_by('published', 'ASC');
$pag = $this->db->get('articles', $config['per_page'], $this->uri->segment(4));         
$data['records'] = $pag->result();

问题在于:在查询之前先执行查询。
先下订单,然后执行查询
在执行以下操作时: db->get会执行查询,如果您具有where条件或order条件,则必须将其放在get命令之前。
尝试这个

$this->db->order_by('published', 'ASC');
$pag = $this->db->get('articles', $config['per_page'], $this->uri->segment(4));  
$data['records'] = $pag->result();

文件资料

暂无
暂无

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

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