我已经使用 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();
?>
//它正在工作,但默认情况下数据是按升序排列的。我该怎么做才能按升序排列?