繁体   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);
}

我正在从教程中创建一个迷你博客应用,并希望添加按ID升序或降序显示博客条目的选项。 上面的代码给了我一个错误,但是我在这里粘贴了它,希望有人能够向我展示正确的方法。 我已经查阅了CI用户手册,但是找不到我想要的任何具体示例,这对于像我这样的新手来说有些困惑。

顺序似乎不对,请在不使用$ 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