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

Order by Appending

Open adeelmughal4u opened this issue 7 years ago • 3 comments
trafficstars

I am trying to use Order by after the following query

$this->remote_jobs->get_many_by($jobs_params);

right now above query result is SELECT * FROM hm_jobs WHERE company_id = '1' AND user_id = '6'

I want to add order by within this query... how I will do it?

adeelmughal4u avatar Jul 13 '18 10:07 adeelmughal4u

this should work:

$this->remote_jobs->order_by('field_to_order_by', 'ASC')->get_many_by($jobs_params);

shayhurley avatar Jul 13 '18 17:07 shayhurley

Thanks, it works. 👍

How I will use WHERE LIKE clause for fetching records from table based on this WHERE LIKE?

adeelmughal4u avatar Jul 14 '18 18:07 adeelmughal4u

It doesn't look like this is implemented currently.

You probably want to copy the order_by function (https://github.com/jamierumbelow/codeigniter-base-model/blob/master/core/MY_Model.php#L747) into a new function for where_like and reference the codeigniter documentation (https://codeigniter.com/user_guide/database/query_builder.html#looking-for-similar-data)

willpower232 avatar Jul 16 '18 08:07 willpower232