title: Codeigniter - Ordering active record alphabetically
body: <p>I was wondering if someone could help me out with something.</p>
  
  <p>I have a bit of ajax that calls a function in my model.</p>
  
  <p>But i cant seem to be able to order the output by 'model'.</p>
  
  <p>Below the function im having trouble with</p>
  
  <pre><code>function get_models_by_brand($tree = null)
  {
      $this-&gt;db-&gt;select('id, model');
  
      if($tree != NULL){
          $this-&gt;db-&gt;where('brand_id', $tree);
      }
  
      $query = $this-&gt;db-&gt;get('models');
      $models = array();
  
      if($query-&gt;result()){
          foreach ($query-&gt;result() as $model) {
              $models[$model-&gt;id] = $model-&gt;model;
          }
          return $models;
      } else {
          return FALSE;
      }
  }
  </code></pre>