I am working on a blogging site in codeigniter.In which the blog is to be listed in the last one first order.ie the last one will be on top.Here in my application variable $blogs contain all the blogs to be listed and the date_created.$blogs will display the blogs,but not in the required order.Now I want to sort the blog by the date_created value.
the main model function that return the blogs is here
public function LoadAllBlogs(){
$blogs = array();
$this->db->select('id');
$this->db->from('blog');
$q= $this->db->get();
foreach ($q->result() as $row) {
$blog = new Blog();
$blog->loadWithLatestPublishedEntry($row->id);
$blogs[] = $blog;
}
return $blogs; //contain all the blogs entry and the date in which blog is created
}
can anyone help me…..
You are going to need to add an ORDER BY clause to your query so they are sorted by your database. It’s pretty simple, pass the
order_by()function a field name and either asc for ascending or desc for descending.