我想知道是否有人可以帮助我解决一些问题。
我有一些 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");
// Produces: ORDER BY title 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)