Php 使用分页(使用codeigniter)时如何按降序获取数据?

Php 使用分页(使用codeigniter)时如何按降序获取数据?,php,codeigniter,pagination,Php,Codeigniter,Pagination,我已经使用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_

我已经使用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);
}
公共功能新闻($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']='';
$config['full_tag_close']='';
$this->pagination->initialize($config);
$data['posts']=$this->db->limit(3,$offset)->get('news')->result();
$this->load->view('inbox\u 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();