2017-03-20 7 views
0

私はこのコードCodeIgniterのget_whereとORDER_BY

これを持っている。これは私のモデル

function get_where_custom($col, $value) { 
    $table = $this->get_table(); 
    $this->db->where($col, $value); 
    $query=$this->db->get($table); 
    return $query; 
} 

ある

function menu() 
{ 
    $data['query'] = $this->get_where_custom('key', 'value'); 
    $data['view_file'] = 'menu'; 
    $this->load->view($data); 
} 

function get_where_custom($col, $value) 
{ 
    $this->load->model('mdl_menu'); 
    $query = $this->mdl_menu->get_where_custom($col, $value); 
    return $query; 
} 

私のコントローラである私は、列名date_postedを持つテーブルに値を示していますデータベース。テーブルをdate_postedで注文したい。私はこれにどうやってアプローチするのですか?

ありがとうございました。以下のようなモデルを使用$this->db->order_by('column_name');

+0

あなたは** "get_where_custom" **関数の内部**ます$ this-> DB-> ORDER_BY($のCOL)を追加することができます。** $ COLをdate_postedとして想定する。 –

答えて

0

function get_where_custom($col, $value) { 
    $table = $this->get_table(); 
    $this->db->order_by('date_posted'); 
    $query = $this->db->get_where($table,array($col=>$value)); 
    return $query; 
}