[英]Codeigniter pagination link is not working
我是CI的新手,所以有人要求帮助我显示分页链接的结果。 在数据库中,我有3条记录,每页显示一条记录。 问题是当我选择下一个分页数字链接时,我的分页链接中没有显示结果。
问题是,当我单击分页链接输出的数字2时,显示结果为空,并且没有得到echo $ data-> email.E的任何值。以下是我的控制器,模型,视图。
我已经尝试了很多方法,但是没有用,即使没有用,我也完全放弃了Google。 我认为问题是当选择分页链接时页面正在加载以从数据库获取第二条记录时,帖子值不再传递给模型页面,所以可能是问题所在。
这是我的控制器。
public function users($limit=1,$offset){
$this->load->helper('url');
$this->load->view('includes/kheader');
$this->load->view('includes/kmenu');
$data = array();
$look = $this->input->post('look');
$age = $this->input->post('age');
$age_from = $this->input->post('age_from');
$age_to = $this->input->post('age_to');
$se_ct = $this->input->post('sect');
$subsect = $this->input->post('subsect');
$coun_try = $this->input->post('country');
$sta_te = $this->input->post('state');
$ci_ty = $this->input->post('city');
$qualification = $this->input->post('qualification');
$results = $this->searchresultss->login($look, $age, $age_to, $age_from, $se_ct, $subsect, $coun_try, $sta_te, $ci_ty, $qualification);
//for base_url()
$this->load->helper('url');
//Pagination Config
$config = array();
// $config['base_url'] = base_url().'searchresult/users';
$config['base_url'] = base_url().'searchresult/users';
$config['total_rows'] = count($results);
$config['per_page'] = $limit;
$this->load->library('pagination', $config);
$data['pagination_links'] = $this->pagination->create_links();
//Reducing the number of results for the view
/** NOTE: This is not the most efficient way **/
//echo $data;
$data['results'] = array_slice($results,$offset,$limit);
$this->load->view('searchresult', $data);
这是我的模特页面
public function login($look, $age, $age_to, $age_from, $se_ct, $subsect, $coun_try, $sta_te, $ci_ty, $qualification)
{
return $this->db->query("SELECT * FROM users WHERE gender = '$look' And status='1'")->result();
}
我也无法通过谷歌获得答案,但是当页面加载的问题是当我选择下一个数字链接的分页链接不起作用时,将显示一条记录。 分页脚本无法正常工作,我认为它与偏移量有关。 所以我不确定是什么错误,所以我在下面发布了我的代码,请仔细阅读并为我提供帮助。
//错误是当我选择下一个分页的数字链接时,未从数据库中获取记录时,我的视图页面中的输出为空结果。因此请您帮助我解决问题,并且缺少更多警告消息,参数2对于Searchresult :: users(),更多错误消息是undefined variable offset。
这是查看页面
if (empty($results)) {
echo 'Results set is empty';
} else {
foreach ($results as $data) {
echo $data->email.'<br />';
}
}
echo $pagination_links;
我是ci iam的新手吗,如果有任何错误,请不要介意寻找可以解决我问题的ci开发人员。
考虑以下示例:
// Pagination Library
$this->load->library('pagination');
$Row_Per_Page = $this->rpp; // or direct assign 10 as int
$Page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
// Only for Query String ?page=2&parm=val&parm2=val2
$this->pagination->suffix = ! empty($QS) ? "?" . $QS : "";
// Configuration Settings
$config['base_url'] = base_url("cpanel/invoices");
$config['total_rows'] = $this->invoice->invoices_count($QS);
$config['per_page'] = $Row_Per_Page;
$config["uri_segment"] = 3;
$config['first_link'] = 'First';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_link'] = 'Last';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="javascript:;">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
// Pass variables to query
// $config["per_page"] -> Row Per Page
// $Page -> Holds the Starting Limit from URI Segment
$this->settings['Invoices'] = $this->invoice->get_invoice_list( $config["per_page"], $Page, $this->input->server('QUERY_STRING') );
$this->settings['Pagination_Link'] = $this->pagination->create_links();
$this->load->view('cpanel/invoice_lists', $this->settings );
阅读代码之间的注释以更好地理解。 希望这对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.