Codeigniter - Ordering active record alphabetically -
i wondering if me out something.
i have bit of ajax calls function in model.
but cant seem able order output 'model'.
below function im having trouble with
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() $model) { $models[$model->id] = $model->model; } return $models; } else { return false; } }
$this->db->order_by();
lets set order clause. first parameter contains name of column order by. second parameter lets set direction of result. options asc or desc, or random.
$this->db->order_by("title", "desc"); // produces: order title descyou can pass own string in first parameter:
$this->db->order_by('title desc, name asc'); // produces: order title desc, name ascor multiple function calls can made if need multiple fields.
$this->db->order_by("title", "desc"); $this->db->order_by("name", "asc"); // produces: order title desc, name asc
Comments
Post a Comment