【发布时间】:2014-09-14 08:41:17
【问题描述】:
请求你帮助分页链接。 在我的数据库中,我有 3 条记录,我想每页显示一条记录。当我选择分页链接的下一个数字时,没有获取数据。事情是,当我单击分页链接的第 2 个数字时,echo var_dump() 显示结果为空,并且我没有得到 echo $data-> 的任何值电子邮件。但是当我第一次搜索时,我能够显示单个记录,问题只是分页的下一个链接那么可能是什么错误?我无法得到答案,我不确定会发生什么,所以我在下面发布我的代码,请仔细阅读并帮助我。 请求你帮助我。
**HERE STARTS MY CONTROLLER**
public function users($limit=1,$offset = 0)
{
$this->load->helper('url');
$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);
$this->load->helper('url');
$config = array();
$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();
$data['results'] = array_slice($results, $offset, $limit);
$this->load->view('searchresult', $data);
$this->load->view('includes/khelp');
$this->load->view('includes/kfooter');
**HERE STARTS MY MODEL PAGE**
Class Searchresultss extends CI_Model
{
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();
}
}
**HERE START MY VIEW PAGE**
echo var_dump($_POST);
if (empty($results)) {
echo 'Results set is empty';
} else
{
foreach ($results as $data) {
echo $data->email.'<br />';
}
}
echo $pagination_links;
【问题讨论】:
-
点击分页链接的第 2 号时会丢失帖子变量
-
好吧,我是新人,你能简单解释一下吗..varun 我会很感激的
-
您在查询中使用了后置变量 $look。当您单击 2 号链接时。 $look 变量中没有任何值
-
好的..所以我需要做些什么改变varun请不要介意你能告诉我更正吗
-
有2个解决方案可用。 1. 将 post 变量移动到会话变量并在创建查询时使用会话变量。 2.在URL中添加所有post变量。
标签: php codeigniter pagination