Codeigniter - Ordering active record alphabetically
$this->db->order_by();
Lets you set an ORDER BY clause. The first parameter contains the nameof the column you would like to order by. The second parameter letsyou set the direction of the result. Options are asc or desc, orrandom.
$this->db->order_by("title", "desc"); // Produces: ORDER BY title DESC
You can also pass your own string in the first parameter:
$this->db->order_by('title desc, name asc'); // Produces: ORDER BY title DESC, name ASC
Or multiple function calls can be made if you need multiple fields.
$this->db->order_by("title", "desc");$this->db->order_by("name", "asc"); // Produces: ORDER BY title DESC, name ASC