2012-06-04 4 views
5

누군가 나를 도와 줄 수 있는지 궁금합니다.Codeigniter - 알파벳순 알파벳순으로 주문하기

모델에 함수를 호출하는 아약스가 약간 있습니다.

하지만 '모델'로 출력을 주문할 수없는 것 같습니다.

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 절을 설정할 수 있습니다. 첫 번째 매개 변수에는 주문하려는 열의 이름 이 포함되어 있습니다. 두 번째 매개 변수를 사용하면 결과 방향을 으로 설정할 수 있습니다. 옵션은 오름차순 또는 내림차순이거나 임의입니다.

$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