在CodeIgniter中,如何检索sql查询,并在查询检索的同一时间通过升序或降序排序?

时间:2022-01-27 01:13:21
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. 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.

我正在创建一个微型博客应用程序从一个教程,想加入的选项显示博客条目的顺序升序或降序的id。上面的代码给了我一个错误但是我贴在这里希望有人能告诉我正确的方法。我查阅了CI用户手册,但找不到我所寻找的任何具体的例子,这让像我这样的新手感到有些困惑。

1 个解决方案

#1


4  

It looks like the order is wrong, put the order-by first without the $info['query']

看起来订单是错误的,把订单放在第一位,没有$info['查询']

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

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

#1


4  

It looks like the order is wrong, put the order-by first without the $info['query']

看起来订单是错误的,把订单放在第一位,没有$info['查询']

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

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