我正在寻找一种使用表库以及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 ["记录"] = $ this-> db-> get(" mail",$ config [" per_page"],$ this-&gt ; input-> get(' per_page',TRUE));
答案 0 :(得分:1)
仅添加您的模型
$this->db->order_by('id', 'asc');//or desc
答案 1 :(得分:0)
更改:
$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();