【问题标题】:Codeigniter - reverse data in tableCodeigniter - 反转表中的数据
【发布时间】:2016-08-13 22:09:59
【问题描述】:

我正在寻找一种使用表格库以及 Codeigniter 中的分页来以相反顺序显示数据的方法。来自

public function pagination(){

    $this->load->library("pagination");
    $this->load->library("table");

    $this->table->set_heading("ID", "Name", "Address");

    $config["base_url"] = site_url('site/pagination');
    $config["total_rows"] = $this->db->get("mail")->num_rows();
    $config["per_page"] = 10;
    $config["num_links"] = 10;
    $config['page_query_string'] = TRUE;


    $this->pagination->initialize($config);

    $data["records"] = $this->db->get("mail", $config["per_page"], $this->input->get('per_page', TRUE)); 
    $data['pagination'] = $this->pagination->create_links();

    $this->load->view("site_header");
    $this->load->view("site_nav");
    $this->load->view("content_about", $data);
    $this->load->view("site_footer");

}

该表工作正常,但我无法找到以相反顺序显示数据的方法。我想让表格从数据库中的最新条目(ID、姓名、地址)开始,而不是第一个。

我想他们查询数据库的方式有问题: $data["records"] = $this->db->get("mail", $config["per_page"], $this->input->get('per_page', TRUE));

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    只添加你的模型

    $this->db->order_by('id', 'asc');//or desc
    

    【讨论】:

      【解决方案2】:

      改变:

      $data["records"] = $this->db->get("mail", $config["per_page"], $this->input->get('per_page', TRUE));
      

      到:

      $data["records"] = $this->db->select("ID, Name, Address")->from("mail")->order_by("ID DESC")->limit($config["per_page"], $offset)->result_array();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-16
        • 2020-03-20
        • 1970-01-01
        相关资源
        最近更新 更多