I am tring to use get_where and order_by like so...
$query = $this->db->get_where($this->tbl_name, $where)->order_by('birth_date', 'ASC');
but got this error...
Fatal error: Call to undefined method CI_DB_mysql_result::order_by() in C:\xampp\htdocs\OAWA\application\models\Member_model.php on line 82
What Am i doing wrong?
In CodeIgniter's Active Record, every method returns the object itself (which allows method chaining) except for get
and get_where
which return the result set.
Thus, what you need to do is:
$query = $this->db->order_by('birth_date', 'ASC')->get_where($this->tbl_name, $where);
i.e. The get_where()
call needs to be the last one. It returns the result set, and so calling order_by()
after get_where()
is attempting to call it on the result set which is invalid.
EDIT
There are other ways to write this query as well:
$query = $this->db->from($this->tbl_name)->where($where)->order_by('birth_date', 'ASC')->get();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With