1
我不知道我在做什么错在这里。我看遍了所有,但找不到我在找什么。我试图按日期排列我的结果。但我不确定是否有助于了解日期在表格中的顺序不正确。我在每个页面上获得了类似的结果,而不是加载下一组记录,并且日期不合适。CodeIgniter分页顺序按日期结果错误,并显示相同的结果
**Model**
<?php
class Topics_Model extends CI_Model {
public $db_table_name = 'px_topics';
function __construct()
{
parent::__construct();
}
public function record_count()
{
return $this->db->count_all($this->db_table_name);
}
public function fetch_topics($limit, $offset)
{
$this->db->limit($limit, $offset);
$this->db->order_by("date", "desc");
$query = $this->db->get($this->db_table_name);
if($query->num_rows() > 0) {
foreach($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return FALSE;
}
}
**Controller**
<?php
class Test extends MY_Controller {
function __construct()
{
parent::__construct();
$this->load->model('user_model');
$this->load->model('topics_model');
$this->load->library('pagination');
}
function index()
{
$data['users'] = $this->user_model->get_all();
$data['sessid'] = $this->user_model->get_by_sess_id();
$data['sessdata'] = $this->user_model->get_session_data();
$data['main_content'] = 'test_view';
$this->load->view('template', $data);
}
function paged()
{
$config = array();
$config["base_url"] = base_url() . "test/paged";
$config["total_rows"] = $this->topics_model->record_count();
$config["per_page"] = 5;
$config["uri_segment"] = 3;
$config["use_page_numbers"] = TRUE;
$config["next_tag_open"] = '<div class="next">';
$config["next_tag_close"] = '</div>';
//$choice = $config["total_rows"]/$config["per_page"];
//$config["num_links"] = round($choice);
$config["num_links"] = "3";
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["results"] = $this->topics_model->fetch_topics($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$data["main_content"] = 'test2_view';
$this->load->view('template', $data);
}
}
可以包括基本URL和分页链接生成一个URL,如果他们通常显示相同的记录的URI段设置不正确 –
我有我的基础URL和索引页面设置就像这样,因为我已经用干净的URL设置了它... $ config ['base_url'] \t =''; $ config ['index_page'] =''; –
是的,但你已经把你的uri段设置为$ config [“uri_segment”] = 3;所以你需要分页参数是类似domain.com/home/pages/$no的东西,如果它不是这样的话,你会得到相同的内容返回你的查询 –