【问题标题】:how to get data in descending order when using pagination(using codeigniter )?使用分页(使用codeigniter)时如何按降序获取数据?
【发布时间】:2013-08-27 12:25:36
【问题描述】:

我已经使用 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();
?>

//它正在工作,但默认情况下数据是按升序排列的。我该怎么做才能按升序排列?

【问题讨论】:

    标签: php codeigniter pagination


    【解决方案1】:

    在你得到消息之前尝试添加这个

    $this->db->order_by("id", "desc");
    $data['posts'] = $this->db->limit(3,$offset)->get('news')->result();
    

    【讨论】:

      猜你喜欢
      • 2016-10-26
      • 2017-03-03
      • 2019-01-23
      • 2016-02-16
      • 2018-04-12
      • 1970-01-01
      • 2016-12-16
      • 1970-01-01
      • 2017-12-21
      相关资源
      最近更新 更多