我是CI的新手,所以大家要求帮我显示分页链接的结果。在数据库中,我有3条记录,我正在为每个页面显示一条记录。 当我选择分页的下一个数字链接时,问题出现在我的分页链接中,结果未显示。
当我点击分页链接输出的数字2时显示结果为空,我没有获得echo $ data-> email.Below的任何值是我的控制器,模型,视图。
我尝试了很多方法,但没有用,即使没有用,我甚至完全按照谷歌。 我认为问题是当页面加载以在选择分页链接时从数据库获取第二条记录后,值不再传递给模型页面,因此可能是问题。
这是我的控制器。
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();
}
我也无法通过谷歌得到答案但是当页面加载问题是我选择下一个数字链接的分页链接时它正在显示一条记录它不起作用。分页脚本无法正常工作我认为它与偏移有关。 那么可能是错误我不确定所以我在下面发布我的代码请仔细阅读并帮助我。
//错误是当我选择分页的下一个数字链接时,记录未从数据库中获取我在视图页面中输出为空结果。请求您帮我解决问题,更多警告信息是Searchresult :: users()缺少参数2,更多错误消息是未定义的变量偏移量。
以下是视图
if (empty($results)) {
echo 'Results set is empty';
} else {
foreach ($results as $data) {
echo $data->email.'<br />';
}
}
echo $pagination_links;
我是不是新来的ci iam正在寻找一个ci开发人员,如果有任何错误可以找到我的问题,请不要介意。
答案 0 :(得分:0)
考虑这个例子:
// 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 );
阅读代码之间的注释以便更好地理解。希望这能帮助你。