**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框架的新手,我试着在我的结果页上以abeobe提到的方式进行分页,当我这样做的时候,我得到了错误不支持的操作数类型,所以请你帮助我致命的错误:H:\xampp\htdocs\kkci\system\libraries\Pagination.php on line 124中不支持的操作数类型是我得到的错误
发布于 2014-07-31 00:37:58
您的问题是,您正在将数组而不是编号分配给$config['total_rows']
您可以通过调用模型中的登录函数来获取此值。
$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);发布于 2014-07-31 10:47:26
在您的模型中执行以下代码
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();
?>希望它能解决你的问题
https://stackoverflow.com/questions/25039502
复制相似问题