CodeIgniter Forums
Order column desc in one query $data - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Order column desc in one query $data (/showthread.php?tid=75546)



Order column desc in one query $data - kelapamuda - 02-20-2020

Hi ,maybe this just simple question, but i don't have answer yet 

My query is this :
$data['employee'] = $this->m_data->get_data('employee')->result();

I want to order descending, i try this 
$data['employee'] = $this->m_data->get_data('employee')->order_by("employee_id desc")->result();
But it gave error like this :


Message: Call to undefined method CI_DB_mysqli_result::order_by()

How to fix the query ?


RE: Order column desc in one query $data - muuucho - 02-20-2020

(02-20-2020, 02:02 AM)kelapamuda Wrote: Hi ,maybe this just simple question, but i don't have answer yet 

My query is this :
$data['employee'] = $this->m_data->get_data('employee')->result();

I want to order descending, i try this 
$data['employee'] = $this->m_data->get_data('employee')->order_by("employee_id desc")->result();
But it gave error like this :


Message: Call to undefined method CI_DB_mysqli_result::order_by()

How to fix the query ?
Every method returns allows for chaning, except get and get_where which returns the result. Try to place order_by() before get_data()


RE: Order column desc in one query $data - dave friend - 02-21-2020

Show the code for m_data->get_data()


RE: Order column desc in one query $data - kelapamuda - 02-27-2020

Finally it works,i just changet the query sentence
$data['tbl_tamu'] = $this->db->query("SELECT * FROM tbl_tamu order by tbl_tamu_id desc")->result();