Is it possible to sort values obtained from MySQL, for example, in descending order of id ?
id
Thanks.
Here you go ...
$this->db->select("*"); $this->db->from("table"); $this->db->order_by("id", "desc"); $this->db->get();
See the codeigniter documentation for the active writer class for more details.
As suggested by ShiVik, you can easily do this with the Active Record class. Also note that you can link your queries together if using PHP 5 +:
$this->db->select('*')->from('table')->order_by('id', 'desc'); $query = $this->db->get();
Example:
$query = $this->db->order_by("id", "desc")->get('table'); if($query->num_rows>0){ foreach ($query->result() as $row){ $names[] = $row->name; } return $names; }