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;     } } 

from documentation,

$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 desc 

you can pass own string in first parameter:

$this->db->order_by('title desc, name asc');  // produces: order title desc, name asc 

or 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

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -