我使用codeigniter库函数进行分页。它有效,但我没有得到如何按降序显示内容。
public function news($offset = 0) {
$this->load->library('pagination');
$config['base_url'] = base_url() . "index.php/homepage/inbox_news";
$config['total_rows'] = $this->db->count_all_results('news');;
$config['per_page'] = 3;
$config['full_tag_open'] = '<div class="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$data['posts'] = $this->db->limit(3, $offset)->get('news')->result();
$this->load->view('inbox_news', $data);
}
//这里的新闻是我在数据库中的表名
在视图页面中,我已经这样做了
<?php
foreach ($posts as $row) {
echo $news = $row->news;
}
echo $this->pagination->create_links();
?>
//它正在工作,但默认情况下数据按升序排列。我该怎么办才能按升序排列?
答案 0 :(得分:3)
尝试在收到新闻之前添加此内容
$this->db->order_by("id", "desc");
$data['posts'] = $this->db->limit(3,$offset)->get('news')->result();