开发者

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?

开发者 https://www.devze.com 2023-02-17 03:07 出处:网络
function index() { $info[\'title\'] = \'Browser Title\'; $info[\'heading\'] = \'Blog Heading\'; $info[\'query\'] = $this->db->get(\'entries\');
function index() {
    $info['title'] = 'Browser Title';
    $info['heading'] = 'Blog Heading';

    $info['query'] = $this->db->get('entries');
    $info['query']开发者_StackOverflow社区 = $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.


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

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

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号