CodeIgniter Forums
where clause with order_by in codeigniter giving me issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: General (https://forum.codeigniter.com/forumdisplay.php?fid=1)
+--- Forum: Lounge (https://forum.codeigniter.com/forumdisplay.php?fid=3)
+--- Thread: where clause with order_by in codeigniter giving me issue (/showthread.php?tid=90497)



where clause with order_by in codeigniter giving me issue - prem16 - 03-27-2024

Hi All,

I am new in codeigniter framework, I have to add order_by in my query..
PHP Code:
$data['work']=$this->work->where('wuFk'session()->get('uId'))->get()->getResult(); 



I want to add the order_by('uName','DESC'), added like below but giving me issue, bad method execptions.
PHP Code:
$data['work']=$this->work->where('wuFk'session()->get('uId'))->order_by('uName','DESC')->get()->getResult();

Do 
you have any suggestion for order_by with where clause in query




  $data['work']=$this->work->where('wuFk', session()->get('uId'))->get()->getResult();


RE: where clause with order_by in codeigniter giving me issue - kenjis - 03-27-2024

Showing the exact error message would make you get better support.


RE: where clause with order_by in codeigniter giving me issue - MMLTech - 03-30-2024

Assuming you are using CI4 and a model, issue may be here ->getResult() you should either use getResultArray() if you expect an array or getResultObject() if you expect an object


RE: where clause with order_by in codeigniter giving me issue - InsiteFX - 04-01-2024

It's orderBy not order_by if your using CodeIgniter 4.x.x


RE: where clause with order_by in codeigniter giving me issue - nahaK - 04-03-2024

(03-27-2024, 12:11 AM)prem16 Wrote: Hi All,



I want to add the order_by('uName','DESC'), added like below but giving me issue, bad method execptions.
PHP Code:
$data['work']=$this->work->where('wuFk'session()->get('uId'))->order_by('uName','DESC')->get()->getResult(); 

Hey hi, use orderBy() instead of order_by()

$data['work']=$this->work->where('wuFk', session()->get('uId'))->order_by('uName','DESC')->get()->getResult();