搜索后的Codeigniter分页错误

时间:2015-04-04 09:46:55

标签: php codeigniter pagination

点击下一页搜索数据后,它不适用于搜索结果。点击后进入第一页。我怎么解决这个问题 ? 谢谢

控制器:

 public function gkclientsadd(){
    $arg["src"] = 0;
    $arg["pageOffset"] = 0;
    $np = $this->uri->segment(3);
    $data["offset"] = 0;
    $this->search_by = 0;

    if($_SERVER['REQUEST_METHOD'] == 'GET')
    {
        if(isset($_GET["client_search"]))
        {
            $arg["login"] = $this->input->get('login');
            $arg["pwd"] = $this->input->get('pwd');
            $arg["basetariff"] = $this->input->get("basetariff");
            $arg["crc"] = $this->input->get("crc");
            $arg["resone"] = $this->input->get("resone");
            $arg["rpp"] = $this->default_rpp;
            $arg["offset"] = $this->default_offset;
            $arg["src"] = 1;

            $this->search_basetariff = $arg["basetariff"];
            $this->search_currency = $arg["crc"];
            $this->search_parent = $arg["resone"];
            $this->search_by = 1;
            //print_r($arg);die;
        } else $arg["src"] = 0;
    }
    if(!empty($np)){
            $arg["pageOffset"] = ($np/$this->default_rpp);
            $arg["rpp"] = $this->default_rpp;
            $arg["offset"] = ($this->default_rpp)*$arg["pageOffset"];
            $data["offset"] = $arg["offset"];
            $arg["src"] = 1;
    }

    $data["gkclientsData"] = $this->admin_model->getGkclients($this->userId, $this->rtc_table,$arg, $this->default_rpp, $this->default_offset); 
    $data["getTotalGk"] = $this->admin_model->getTotalGk($this->rtc_table,$arg);
    $data["totalRecords"] = count($data["getTotalGk"]);
    $data["totalPage"] = $data["totalRecords"]/$this->default_rpp;
    $data["Page"] = $arg["pageOffset"]+1;

    $config = array();
    $config["base_url"] = base_url() . "index.php/admin/gkclientsadd";
    $config["total_rows"] = $data["totalRecords"] ;
    $config["per_page"] = $this->default_rpp;
    $config["uri_segment"] = 3;
    $config['first_url'] = $config['base_url'].'?'.http_build_query($_GET);
    $this->pagination->initialize($config);
    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $data["links"] = $this->pagination->create_links(); 

    $this->load->view('admin/clients/gkclientsadd',$data);
}

型号:

public function getGkclients($userId, $rtc_table,$arg, $default_rpp,$default_offset)  
{
    $this->load->database();
    if($arg['src']== 1){
        $whr = "";
        $rpp = "";
        $offset = "";
    if(!empty($arg["rpp"])) $rpp .= " LIMIT ".$arg["rpp"]."";
    if(!empty($arg["offset"])) $offset .= " OFFSET ".$arg["offset"]."";

    if(!empty($arg["login"])) $whr .= " AND $rtc_table.login = '".$arg["login"]."'";
    if(!empty($arg["pwd"])) $whr .= " AND $rtc_table.password = '".$arg["pwd"]."'";
    if(!empty($arg["basetariff"])) $whr .= " AND $rtc_table.id_tariff = '".$arg["basetariff"]."'";
    if(!empty($arg["crc"])) $whr .= " AND $rtc_table.id_currency = '".$arg["crc"]."'";
    if(!empty($arg["resone"])) $whr .= " AND $rtc_table.id_res = '".$arg["resone"]."'";

    } else {
        $whr="";
        $rpp= "Limit $default_rpp"; 
        $offset= "OFFSET $default_offset"; 
    }

    $query = "SELECT DISTINCT $rtc_table.id_client,$rtc_table.id_res,$rtc_table.login,$rtc_table.password,$rtc_table.id_tariff,
                $rtc_table.account_state,$rtc_table.type,$rtc_table.type2,currency_names.name
                        FROM $rtc_table, currency_names
                            WHERE currency_names.id = $rtc_table.id_currency $whr
                                order by $rtc_table.login ASC $rpp $offset"; 

    $query_result = $this->db->query($query);
    $gkData=$query_result->result();

    return $gkData;
}

http://i.stack.imgur.com/yMa6d.jpg

0 个答案:

没有答案