Reputation: 5308
Is it possible to sort the values retrieved from MySQL, in say descending id
?
Thanks.
Upvotes: 4
Views: 10150
Reputation: 429
An exemple:
$query = $this->db->order_by("id", "desc")->get('table');
if($query->num_rows>0){
foreach ($query->result() as $row){
$names[] = $row->name;
}
return $names;
}
Upvotes: 2
Reputation: 3698
As ShiVik suggested, you can do this via the Active Record class quite easily. Also note that you can chain your queries together if you are using PHP 5+:
$this->db->select('*')->from('table')->order_by('id', 'desc');
$query = $this->db->get();
Upvotes: 5
Reputation: 10071
Here you go...
$this->db->select("*");
$this->db->from("table");
$this->db->order_by("id", "desc");
$this->db->get();
Read more over in codeigniter documentation for active record class.
Upvotes: 7