我使用了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();
?>
//它正在工作,但默认情况下数据按升序排列。我该怎么做才能把它按升序排列?
在获得新闻之前尝试添加此内容
$this->db->order_by("id", "desc");
$data['posts'] = $this->db->limit(3,$offset)->get('news')->result();