CodeIgniter - ORDER BY对查询 [英] CodeIgniter - ORDER BY on a query

查看:446
本文介绍了CodeIgniter - ORDER BY对查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常小的脚本从数据库表中获取所有记录,代码如下

  $ query = $ this-> db-> get($ this-> table_name); 
return $ query-> result();

使用此语法,我将如何ORDER BY'name'?




h2_lin>解决方案

我相信get()函数立即运行选择查询,不接受ORDER BY条件作为参数。我想你需要单独声明条件,然后运行查询。试试。

  $ this-> db-> from($ this-> table_name); 
$ this-> db-> order_by(name,asc);
$ query = $ this-> db-> get();
return $ query-> result();


I have a very small script to get all records from a database table, the code is below

$query = $this->db->get($this->table_name);
return $query->result();

using this syntax, how would i ORDER BY 'name' ?

I get errors everytime i stick the order by bit on the end.

Cheers,

解决方案

I believe the get() function immediately runs the selection query and does not accept ORDER BY conditions as parameters. I think you'll need to separately declare the conditions, then run the query. Give this a try.

$this->db->from($this->table_name);
$this->db->order_by("name", "asc");
$query = $this->db->get(); 
return $query->result();

这篇关于CodeIgniter - ORDER BY对查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆