php - How do I get my CMS website to show the newest record? -
i making content managed website in codeigniter, when read out array foreach shows oldest record @ top.
how can make newest record on top.
this 1 of functions in controller.
function comments($page){ $this->load->library('pagination'); $this->load->model("model_get"); $config['base_url'] = base_url('main/comments/'.$this->uri->segment(3).'/'); $config['total_rows'] = $this->model_get->getcommentcount(); $config['per_page'] = 5; $config['uri_segment'] = 4; $this->pagination->initialize($config); $data["results"] = $this->model_get->getcomments($config['per_page'], $page); $this->load->view('content_comment', $data); }
this model fetch data.
function getcomments($limit, $start){ $this->db->from('comments'); $this->db->where('blog_id', $this->uri->segment(3)); $this->db->limit($limit, $this->uri->segment(4)); $results = $this->db->get(); if ($results) { return $results->result(); }else{ return false; } }
and foreach display results.
<?php foreach($results $row){ $text = $row->text; echo "<h3>". $text ."</h3>"; $author = $row->author; echo "<p>". $author ."</p>"; }
add line model function after "limit" line:
$this->db->order_by("blog_id", "desc");
Comments
Post a Comment