gpt4 book ai didi

Codeigniter - 按字母顺序排列事件记录

转载 作者:行者123 更新时间:2023-12-03 12:21:29 24 4
gpt4 key购买 nike

我想知道是否有人可以帮我解决一些问题。

我有一些 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;
}
}

最佳答案

From the documentation ,

$this->db->order_by();

Lets you set an ORDER BY clause. The first parameter contains the nameof the column you would like to order by. The second parameter letsyou set the direction of the result. Options are asc or desc, orrandom.

$this->db->order_by("title", "desc"); 
// Produces: ORDER BY title DESC

You can also pass your own string in the first parameter:

$this->db->order_by('title desc, name asc'); 
// Produces: ORDER BY title DESC, name ASC

Or multiple function calls can be made if you need multiple fields.

$this->db->order_by("title", "desc");
$this->db->order_by("name", "asc");
// Produces: ORDER BY title DESC, name ASC

关于Codeigniter - 按字母顺序排列事件记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10883848/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com