简体   繁体   English

在CodeIgniter中,如何在查询检索的同时检索sql查询并按升序或降序对其进行排序?

[英]In CodeIgniter, how do I retrieve a sql query and order it by either ascending or descending order at the same time of query retrieval?

function index() {
    $info['title'] = 'Browser Title';
    $info['heading'] = 'Blog Heading';

    $info['query'] = $this->db->get('entries');
    $info['query'] = $this->db->order_by('id', 'asc');

    $this->load->view('blog_view', $info);
}

I'm creating a mini blog app from a tutorial and wanted to add in the option of displaying blog entries in order of ascending or descending by id. 我正在从教程中创建一个迷你博客应用,并希望添加按ID升序或降序显示博客条目的选项。 The code above gives me an error but I pasted it up here hoping someone would be able to show me the correct way to do it. 上面的代码给了我一个错误,但是我在这里粘贴了它,希望有人能够向我展示正确的方法。 I've consulted the CI user manual but couldn't find any specific examples of what I"m looking for, which makes it somewhat confusing for a newbie like me. 我已经查阅了CI用户手册,但是找不到我想要的任何具体示例,这对于像我这样的新手来说有些困惑。

It looks like the order is wrong, put the order-by first without the $info['query'] 顺序似乎不对,请在不使用$ info ['query']的情况下将其放在第一位

$info['title'] = 'Browser Title';
$info['heading'] = 'Blog Heading';

$this->db->order_by('id', 'asc');
$info['query'] = $this->db->get('entries');

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

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