|
查询数据时,点下一页没问题,但向前返回到第一页时,就无法获取数据,通过查看路径得知是无法获取数据查询起码位置
如:每页20条记录
第二页
xxx/xxx/20
第三页
xxx/xxx/40
当返回第一页时路径为
xxx/xxx/
因此无法获取第一页数据
控制器:
PHP复制代码 function customer_list ()//查询客户资料列表页
{
$this->load->library('pagination');
$this->load->model('Madmin');
$data['baseurl'] = $this->base_url;
$data['get_data'] = FALSE;
$data['get_category'] = $this->Madmin->get_category();
//$this->load->library('form_validation');
//$this->form_validation->set_rules('SearchText', 'Username', 'required');
//$this->form_validation->set_rules('category_id', 'Username', 'required|');
$action = $this->input->post('act');
// if ($action == 'del' or $action == 'move'){
// $ids = $_POST['ID'];
// print_r($ids);
// }
$ic_number = $this->input->post('ic_number');
$phone = $this->input->post('phone');
$post_code = $this->input->post('post_code');
$sex = $this->input->post('sex');
$cureent_rows = $this->uri->segment(5,0);
if (strlen($ic_number) > 0 or strlen($phone) > 0 or strlen($post_code) > 0 or $this->uri->segment(5,0)>0){
if (strlen(trim($post_code))==0){
$post_code = $this->uri->segment(3,0);
}
if (strlen(trim($sex))==0){
$sex = $this->uri->segment(4,0);
}
$data['total'] = $this->Madmin->search_customer_total($ic_number,$phone,$post_code,$sex);
$config['total_rows'] = $data['total'];
$config['per_page'] = 20;
$config['uri_segment'] = 5;
$config['num_links'] = 4;
$config['base_url'] = $this->base_url.'index.php/admin/customer_list/'.$post_code.'/'.$sex.'/';
$config['first_link'] = "<img src='../images/Main/first.gif' border='0'>";
$config['last_link'] = "<img src='../images/Main/last.gif' border='0'>";
$config['next_link'] = "<img src='../images/Main/next.gif' border='0'>";
$config['prev_link'] = "<img src='../images/Main/back.gif' border='0'>";
$this->pagination->initialize($config);
$data['get_customer_list'] = $this->Madmin->search_customer_list_page($ic_number,$phone,$post_code,$sex,$cureent_rows,$config['per_page']);
$data['get_data'] = TRUE;
}
$this->load->view('customer/customer_list',$data);
}
复制代码
模型:
PHP复制代码 //返回查询数据的记录数
function search_customer_total ($ic_number,$phone,$post_code,$sex)
{
$sql = "SELECT * FROM `customer`";
$i = 0;
if (strlen($ic_number)>0){
$i = $i + 1;
$sql = $sql . " WHERE ic_number='$ic_number'";
}
if (strlen($phone)>0){
$i = $i + 1;
if ($i==1) {
$sql = $sql . " WHERE mobile_phone LIKE '%$phone%' OR other_phone LIKE '%$phone%'";
}else{
$sql = $sql . " and (mobile_phone LIKE '%$phone%' OR other_phone LIKE '%$phone%')";
}
}
if (strlen($post_code)>0 and $post_code!=='0'){
$i = $i + 1;
if ($i==1){
$sql = $sql . " WHERE postcode='$post_code'";
}else{
$sql = $sql . " and postcode='$post_code'";
}
}
if ($sex > 0){
$sql = $sql . " and sex=$sex";
}
$sql = $sql . " ORDER BY id DESC";
$query = $this->db->query($sql);
return $query->num_rows();
}
//查询客户数据并分页显示
function search_customer_list_page ($ic_number,$phone,$post_code,$sex,$offset,$limit)
{
$sql = "SELECT * FROM `customer`";
$i = 0;
if (strlen($ic_number)>0){
$i = $i + 1;
$sql = $sql . " WHERE ic_number='$ic_number'";
}
if (strlen($phone)>0){
$i = $i + 1;
if ($i==1) {
$sql = $sql . " WHERE mobile_phone LIKE '%$phone%' OR other_phone LIKE '%$phone%'";
}else{
$sql = $sql . " and (mobile_phone LIKE '%$phone%' OR other_phone LIKE '%$phone%')";
}
}
if (strlen($post_code)>0 and $post_code!=='0'){
$i = $i + 1;
if ($i == 1){
$sql = $sql . " WHERE postcode='$post_code'";
}else{
$sql = $sql . " and postcode='$post_code'";
}
}
if ($sex > 0){
$sql = $sql . " and sex=$sex";
}
$sql = $sql . " ORDER BY id DESC LIMIT $offset,$limit";
$query = $this->db->query($sql);
return $query->result();
}
复制代码 |
|