2012-04-08 4 views
0

나는 페이지 매김을 사용하여 검색을 구현했습니다. 나는 사용자 ID를 갖는 FNAME 등의 검색은 사용자 이름을 기반으로 등록 테이블에서 검색하고페이지 매김이있는 코드 서명자 검색

public function search_result($limit,$start,$search_name) 
{ 
    $this->db->limit($limit, $start); 
    $this->db->select('user_id'); 
    $this->db->where('category',1); 
    $this->db->like('first_name',$search_name); 
    $query = $this->db->get('registration'); 
    if ($query->num_rows() > 0) { 

     foreach ($query->result() as $row) { 

      $data[] = $row; 

     } 

     return $data; 

    } 

    return false; 




} 

컨트롤러 기능`공공 기능 검색() {

if($_POST) 
    { 
     $search_name=$this->input->post('search_name'); 
     $config['base_url'] = 'search'; 
     $config['total_rows'] = 15;//$this->registration_model->record_count(); 
     $config['per_page'] = 4; 
     $config["uri_segment"] = 3; 
     $config['use_page_numbers'] = TRUE; 
     $this->pagination->initialize($config); 
     $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0; 
     $data['result']=$this->institute_model->search_result($config["per_page"],$page,$search_name); 
     $data['links'] = $this->pagination->create_links(); 
     $this->load->view('institute/search',$data); 
    } 
}` 

그리고 모델 기능 코드입니다. 그것은 나를 위해 일하지만 페이지 2를 클릭하면 페이지 번호가 http://localhost/mypro/index.php/institute/search/2이되며 비어있게됩니다. 로드보기 전에

+5

좋습니다. 자, 지금까지 무엇을 했습니까? 또는 기성 스크립트를 원하십니까? –

+0

다음 튜토리얼을 따르십시오 : http://www.w3schools.com/php/php_ajax_livesearch.asp 문제가 생기면 먼저 조사를 해보십시오. 여전히 해결책을 찾을 수 없다면 여기에 도움을 요청하십시오. 지금까지 시도한 것을 질문하십시오. – alxbrd

답변

0

사용 플러그인 Jquery Pagintation

추가 JQuery와.

//Define model function with limit 
public function modelFunction($limit=0) 
    { 
     $this->db->select("....col_name...."); 
      //.................... 
      //......... 
     $this->db->limit(10,$limit)->order_by('id', 'desc'); 
     return $this->db->get()->result_array(); 

    } 



//Define controller function with limit 
function controllerFunction($limit = 0) 
    { 
     $config['base_url'] = path_to_controllerFunction 
     $config['total_rows'] = call_to_total_count_function; 
     $config['per_page'] = 10; 
     $data["total"] = call_to_total_count_function; 
     $config['use_page_numbers'] = TRUE; 
     $data["per_page"] = 10; 
     $config['full_tag_open'] = "<div class = 'pagination'>"; 
     $config['full_tag_close'] = "</div>"; 
     //$config['additional_param'] = 'serialize_form()'; 
     $config['div'] = '#div_to_load_result'; /* Here #content is the CSS selector for target DIV */ 
     //$config['js_rebind'] = "alert('it works !!'); "; /* if you want to bind extra js code */ 
     $this->load->library('table'); 
     $this->jquery_pagination->initialize($config); 
     $html = $this->jquery_pagination->create_links(); 
     $html .= '<br>'; 
     //$this->table->function = 'htmlspecialchars'; 
     //$this->table->set_heading('Delivery','image','time','delivery','old'); 
     $html .= $this->table->generate($this->modelname->modelFunction($limit)); 

     echo $html; 
    } 


     // first time loading result in controller 
function index() 
    { 
     $config['base_url'] = controllerFunction 
     $config['total_rows'] = total_number_of_result; 
     $config['per_page'] = 10; 
     $data["total"] = total_number_of_result 
     $data["per_page"] = 10; 
     $config['use_page_numbers'] = TRUE; 
     $config['full_tag_open'] = "<div class = 'pagination'>"; 
     $config['full_tag_close'] = "</div>"; 
     //$config['additional_param'] = 'serialize_form()'; 
     $config['div'] = '#div_to_load_result'; /* Here #content is the CSS selector for target DIV */ 
     //$config['js_rebind'] = "alert('it works !!'); "; /* if you want to bind extra js code */ 
     $this->load->library('table'); 
     $this->jquery_pagination->initialize($config); 
     $data['html'] = $this->jquery_pagination->create_links().'<br>'.$this->table->generate($this->modelname->modelFunction()); 

     $this->theme->view(path_of_view, $data); 
    } 
// now in view add following line 
<div id="div_to_load_result"><?php echo $html; ?></div> 
관련 문제