codeigniter-base-model icon indicating copy to clipboard operation
codeigniter-base-model copied to clipboard

Select specific fields

Open markdave27 opened this issue 9 years ago • 4 comments
trafficstars

Hi,

How can you return only selected fields using all get functions (get(), get_by(), get_many(), get_many_by() and get_all()). Fetching all the columns of the database/record is not that fast or ideal I believe. Though I can do a filtering of the returned object data but still the delay was already made during the query. I how you can give me an advice on how to make this happen. Thank you in advance.

markdave27 avatar Jan 09 '16 19:01 markdave27

write method

public function select($what = '*', $escape = true) {
    $this->_database->select($what, $escape); return $this; 
}

usage

$this->article_model->select('id, title')->get_all();

michail1982 avatar Jan 10 '16 18:01 michail1982

Thanks for the suggestion michail1982, I'll take note of this and try it out. :+1:

markdave27 avatar Jan 19 '16 23:01 markdave27

public function your_select(){ $this->db->select('id,field1,field2'); return $this; }

thuc101 avatar Aug 24 '19 00:08 thuc101

$this->article_model->your_select()->get_all();

thuc101 avatar Aug 24 '19 00:08 thuc101