Reputation: 33
I am bit new to CI.I want to sort my database values in descending order using this query below in my model. However, it doesn't work form me and throw errors .please help me out.
function get_records(){
$this->db->from($this->tbl_contactus);
$this->db->order_by("contactus_id", "asc");
$query = $this->db->get();
return $query->result();
}
The error:
Upvotes: 2
Views: 14824
Reputation: 86
Try like this
function get_records(){
$this->db->select("*");
$this->db->from("tbl_contactus");
$this->db->order_by("contactus_id", "desc");
$query = $this->db->get();
return $query->result();
}
and also you can use this
function get_records(){
$this->db->select()->from('tbl_contactus')->order_by('contactus_id', 'desc');
}
Upvotes: 3
Reputation: 37233
you have to check $tbl_contactus
because its not defined or empty in that line
$this->db->from($this->tbl_contactus);
You are using query like that:
SELECT * ORDER BY contactus_id ASC
while it should be
SELECT * FROM your_table ORDER BY contactus_id ASC
Upvotes: 1