2012-06-04 5 views
5

誰かが私を助けてくれたらと思っていました。Codeigniter - アルファベット順にアクティブなレコードを注文する

モデルに関数を呼び出す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; 
    } 
} 
+2

'ます$ this-> DB-> ORDER_BY( 'モデル')'? –

答えて

18

From the documentationを持つ関数イム苦労以下

ます$ this-> DB-> ORDER_BY();

ORDER BY句を設定できます。最初のパラメータには、注文する列の名前 が含まれています。 2番目のパラメータでは、結果の方向を に設定します。オプションは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 
関連する問題