Codeigniter-表中的反向数据


Codeigniter - reverse data in table

我正在寻找一种方法,使用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));

更改:

$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();

仅在您的模型中添加

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