Codeigniter-按字母顺序排列活动记录

Codeigniter-按字母顺序排列活动记录,codeigniter,Codeigniter,我想知道是否有人能帮我做点什么 我有一点ajax,它在我的模型中调用一个函数 但我似乎无法按“模型”排序输出 下面的功能我有麻烦了 function get_models_by_brand($tree = null) { $this->db->select('id, model'); if($tree != NULL){ $this->db->where('brand_id', $tree); } $query = $t

我想知道是否有人能帮我做点什么

我有一点ajax,它在我的模型中调用一个函数

但我似乎无法按“模型”排序输出

下面的功能我有麻烦了

function get_models_by_brand($tree = null)
{
    $this->db->select('id, model');

    if($tree != NULL){
        $this->db->where('brand_id', $tree);
    }

    $query = $this->db->get('models');
    $models = array();

    if($query->result()){
        foreach ($query->result() as $model) {
            $models[$model->id] = $model->model;
        }
        return $models;
    } else {
        return FALSE;
    }
}
,

$this->db->order_by()

用于设置ORDER BY子句。第一个参数包含名称 您要按其排序的列的。第二个参数是 您可以设置结果的方向。选项为asc或desc,或 随机的

您还可以在第一个参数中传递自己的字符串:

$this->db->order_by('title desc, name asc'); 
// Produces: ORDER BY title DESC, name ASC
或者,如果需要多个字段,可以进行多个函数调用

$this->db->order_by("title", "desc");
$this->db->order_by("name", "asc"); 
// Produces: ORDER BY title DESC, name ASC
$this->db->order\u by('model')
$this->db->order_by("title", "desc");
$this->db->order_by("name", "asc"); 
// Produces: ORDER BY title DESC, name ASC