**This is my controller**
$this->load->library("pagination");
$this->load->helper('url');
$this->load->view('includes/kheader');
$this->load->view('includes/kmenu');
$per_page=$this->input->post('per_page');
$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');
$data['base']=$this->config->item('base_url');
$data['title']= 'Message form';
$this->load->model("searchresultss");
$per_pg=1;
$offset=$this->uri->segment(2);
$total=$this->searchresultss->login($per_pg,$offset,$per_page,$look,$age, $age_to,$age_from,$se_ct,$subsect,$coun_try,$sta_te, $ci_ty, $qualification);
$this->load->library('pagination');
$config['base_url'] = $data['base'].'/searchresult/users/';
$config['total_rows'] = $total;
$config['per_page'] = $per_pg;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$data['pagination']=$this->pagination->create_links();
$data['query']=$this->searchresultss->login($per_pg,$offset,$per_page,$look,$age, $age_to,$age_from,$se_ct,$subsect,$coun_try,$sta_te, $ci_ty,$qualification);
$this->load->view('searchresult',$data);
**这是我的模型**
public function login($per_page=3,$look,$age,$age_to,$age_from,$se_ct,$subsect,$coun_try, $sta_te, $ci_ty,$qualification,$per_pg,$offset)
{
$query=$this->db->get('users',$per_pg,$offset);
return $query->result();
}
public function message_count()
{
return $this->db->count_all("SELECT *
FROM users
WHERE
if('$se_ct'!='',sect = '$se_ct' AND if('$subsect' !='',subsect = '$subsect',subsect like '%%'),sect like '%%' AND subsect like '%%')
AND
IF( '$coun_try' !='', country = '$coun_try'
AND
if('$sta_te' !='', state = '$sta_te'
AND
if('$ci_ty' !='',city = '$ci_ty',city like '%%'),state LIKE '%%'
AND city LIKE '%%'), country LIKE '%%'
AND state LIKE '%%'
AND city LIKE '%%' )
AND age >= '$age_from'
AND age <= '$age_to'
AND
IF('$qualification' !='',qualification = '$qualification', qualification LIKE '%%' )
And gender = '$look'
And status='1'");
}
我是新的ci框架的事情是,我试图把分页在我的结果页在上面提到的方式,当我这样做我得到错误不支持的操作数'libraries'pagination.php所以请求你帮助我致命错误:H:'xampp'htdocs'kkci'system'libraries'Pagination.php on line 124
中不支持的操作数类型是我得到的错误
您的问题是您正在分配数组而不是数字到$config['total_rows']
您可以通过调用模型中的login函数来获得这个值。
$total=$this->searchresultss->login($per_pg,$offset,$per_page,$look,$age,
$age_to,$age_from,$se_ct,$subsect,$coun_try,$sta_te, $ci_ty, $qualification);
然后赋值给$config['total_rows'] = $total;
然而,在你的模型中,函数被写为返回一个数组:
public function login($per_page=3,$look,$age,$age_to,$age_from,$se_ct,
$subsect,$coun_try, $sta_te, $ci_ty,$qualification,$per_pg,$offset)
{
$query=$this->db->get('users',$per_pg,$offset);
return $query->result(); //this is an array that is returned
}
要解决这个问题,我认为您可以将结果集的计数分配给total_rows变量:
$config['total_rows'] = count($total);
在您的模型中执行以下代码
function message_count()
{
$q=$this->db-get('tbl_name');
return $q->num_rows();
}//now your code in count was correct, or if you want to query your sql syntax the code below
function message_count()
{
$q= $this->db->query("SELECT *
FROM users
WHERE
if('$se_ct'!='',sect = '$se_ct' AND if('$subsect' !='',subsect = '$subsect',subsect like '%%'),sect like '%%' AND subsect like '%%')
AND
IF( '$coun_try' !='', country = '$coun_try'
AND
if('$sta_te' !='', state = '$sta_te'
AND
if('$ci_ty' !='',city = '$ci_ty',city like '%%'),state LIKE '%%'
AND city LIKE '%%'), country LIKE '%%'
AND state LIKE '%%'
AND city LIKE '%%' )
AND age >= '$age_from'
AND age <= '$age_to'
AND
IF('$qualification' !='',qualification = '$qualification', qualification LIKE '%%' )
And gender = '$look'
And status='1'");
return $q->num_rows();
}
在之后,执行下面的代码来分页
public function login($per_page=3,$look,$age,$age_to,$age_from,$se_ct,$subsect,$coun_try, $sta_te, $ci_ty,$qualification,$per_pg,$offset)
{
$query=$this->db->get('users',$per_pg,$offset);
return $query; //don't append the ->result() in the return of of this code when using pagination
}
在你的控制器
$data['records']=$this->model_name->login($parameters here);
$this->load->view('view_name',$data);
在视图中执行以下代码
<?php
echo $this->table->generate($records);
echo $this->pagination->create_links();
?>
希望它能解决你的问题