2017-11-19 1 views
0

입력 데이터를 기반으로 데이터베이스에서 데이터를 가져옵니다.
예 : 양식에서 성을 검색하면 성 데이터를 가져와야합니다. AND 또는 OR 연산자 버튼을 사용하여 모든 필드 검색에 성공했습니다.다음 레코드 검색시 데이터를 가져올 수 없습니다. 빈 필드를 나타내는 첫 번째 레코드가 표시됩니다.

그러나 단 하나의 레코드 만 얻고 있지만 검색 기준에 따라 다른 레코드를 얻지 못하는 페이지 매김 문제가 있습니다.

여기 템플릿 라이브러리를 사용하여 페이지를 포함하고 있습니다. 여기서 상기 형태 이미지

enter image description here

나 검색 기록을 따라 동일한 view..and 페이지 매김 링크에 표시해야 모든 필드에 텍스트를 입력함으로써 특정 레코드를 검색 할 경우에 필요한

초기 형태가 비어

모델 :

public function search_record() 

{ 
       $id= $this->input->get('id'); 
       $name= $this->input->get('lname'); 
       $fname= $this->input->get('fname'); 
       $pdate= $this->input->get('pdate'); 
       $adate= $this->input->get('adate'); 
       $client= $this->input->get('client'); 
       $bw= $this->input->get('bw'); 
       $color= $this->input->get('color'); 
       $digital= $this->input->get('digital'); 
       $famous= $this->input->get('famous'); 
       $place= $this->input->get('place'); 
       $concept= $this->input->get('concept'); 
       $thing= $this->input->get('thing'); 
       $oldid= $this->input->get('oldid'); 
       $note= $this->input->get('note'); 



//   $condition = array('id_photo' =>$id); 
//   $condition2=array('lastname'=>$name); 
//   $condition3=array('firstname'=>$fname);      
//   $condition4=array('photo_date'=>$pdate); 
//    

      $this->db->select('photo_id,lastname,firstname,bw,color,digital,famous,place,concept,thing,client,photo_date,add_date,note,id_photo'); 
      $this->db->from('tblphotomstr'); 
      $strWhere = ""; 
      if($id != NULL){ 
       $strWhere = "id_photo like "."'%$id%'"; 
      } 
      if($name != NULL){ 
       $opt = $this->input->get('and'); 


       if($opt==1) 
        { 
        if($strWhere != "") 
         { 
         $strWhere = $strWhere." and lastname like "."'%$name%'"; 
        }else{ 
         $strWhere = "lastname like "."'%$name%'"; 
        } 
       } 
       if($opt==2) 
        { 
        if($strWhere != ""){ 
         $strWhere = $strWhere." or lastname like "."'%$name%'"; 
        }else{ 
         $strWhere = "lastname like "."'%$name%'"; 
        } 
       } 
      } 
      if($fname != NULL){ 
       $opt = $this->input->get('and'); 


       if($opt==1) 
        { 
        if($strWhere != "") 
         { 
         $strWhere = $strWhere." and firstname like "."'%$fname%'"; 
        }else{ 
         $strWhere = "firstname like "."'%$fname%'"; 
        } 
       } 
       if($opt==2) 
        { 
        if($strWhere != ""){ 
         $strWhere = $strWhere." or firstname like "."'%$fname%'"; 
        }else{ 
         $strWhere = "firstname like "."'%$fname%'"; 
        } 
       } 
      } 
      if($pdate != NULL){ 
       $opt = $this->input->get('and'); 


       if($opt==1) 
        { 
        if($strWhere != "") 
         { 
         $strWhere = $strWhere." and photo_date like "."'%$pdate%'"; 
        }else{ 
         $strWhere = "photo_date like "."'%$pdate%'"; 
        } 
       } 
       if($opt==2) 
        { 
        if($strWhere != ""){ 
         $strWhere = $strWhere." or photo_date like "."'%$pdate%'"; 
        }else{ 
         $strWhere = "photo_date like "."'%$pdate%'"; 
        } 
       } 
      } 
      if($adate != NULL){ 
       $opt = $this->input->get('and'); 


       if($opt==1) 
        { 
        if($strWhere != "") 
         { 
         $strWhere = $strWhere." and add_date like "."'%$adate%'"; 
        }else{ 
         $strWhere = "add_date like "."'%$adate%'"; 
        } 
       } 
       if($opt==2) 
        { 
        if($strWhere != ""){ 
         $strWhere = $strWhere." or add_date like "."'%$adate%'"; 
        }else{ 
         $strWhere = "add_date like "."'%$adate%'"; 
        } 
       } 
      } 
      if($client != NULL){ 
       $opt = $this->input->get('and'); 


       if($opt==1) 
        { 
        if($strWhere != "") 
         { 
         $strWhere = $strWhere." and client like "."'%$client%'"; 
        }else{ 
         $strWhere = "client like "."'%$client%'"; 
        } 
       } 
       if($opt==2) 
        { 
        if($strWhere != ""){ 
         $strWhere = $strWhere." or client like "."'%$client%'"; 
        }else{ 
         $strWhere = "client like "."'%$client%'"; 
        } 
       } 
      } 
      if($bw != NULL){ 
       $opt = $this->input->get('and'); 


       if($opt==1) 
        { 
        if($strWhere != "") 
         { 
         $strWhere = $strWhere." and client like "."'%$bw%'"; 
        }else{ 
         $strWhere = "client like "."'%$bw%'"; 
        } 
       } 
       if($opt==2) 
        { 
        if($strWhere != ""){ 
         $strWhere = $strWhere." or client like "."'%$bw%'"; 
        }else{ 
         $strWhere = "client like "."'%$bw%'"; 
        } 
       } 
      } 
      if($color != NULL){ 
       $opt = $this->input->get('and'); 


       if($opt==1) 
        { 
        if($strWhere != "") 
         { 
         $strWhere = $strWhere." and client like "."'%$color%'"; 
        }else{ 
         $strWhere = "client like "."'%$color%'"; 
        } 
       } 
       if($opt==2) 
        { 
        if($strWhere != ""){ 
         $strWhere = $strWhere." or client like "."'%$color%'"; 
        }else{ 
         $strWhere = "client like "."'%$color%'"; 
        } 
       } 
      } 
      if($digital != NULL){ 
       $opt = $this->input->get('and'); 


       if($opt==1) 
        { 
        if($strWhere != "") 
         { 
         $strWhere = $strWhere." and client like "."'%$digital%'"; 
        }else{ 
         $strWhere = "client like "."'%$color%'"; 
        } 
       } 
       if($opt==2) 
        { 
        if($strWhere != ""){ 
         $strWhere = $strWhere." or client like "."'%$digital%'"; 
        }else{ 
         $strWhere = "client like "."'%$digital%'"; 
        } 
       } 
      } 
      if($famous != NULL){ 
       $opt = $this->input->get('and'); 


       if($opt==1) 
        { 
        if($strWhere != "") 
         { 
         $strWhere = $strWhere." and client like "."'%$famous%'"; 
        }else{ 
         $strWhere = "client like "."'%$famous%'"; 
        } 
       } 
       if($opt==2) 
        { 
        if($strWhere != ""){ 
         $strWhere = $strWhere." or client like "."'%$digital%'"; 
        }else{ 
         $strWhere = "client like "."'%$digital%'"; 
        } 
       } 
      } 
      if($place != NULL){ 
       $opt = $this->input->get('and'); 


       if($opt==1) 
        { 
        if($strWhere != "") 
         { 
         $strWhere = $strWhere." and client like "."'%$place%'"; 
        }else{ 
         $strWhere = "client like "."'%$place%'"; 
        } 
       } 
       if($opt==2) 
        { 
        if($strWhere != ""){ 
         $strWhere = $strWhere." or client like "."'%$place%'"; 
        }else{ 
         $strWhere = "client like "."'%$place%'"; 
        } 
       } 
      } 
      if($concept != NULL){ 
       $opt = $this->input->get('and'); 


       if($opt==1) 
        { 
        if($strWhere != "") 
         { 
         $strWhere = $strWhere." and client like "."'%$concept%'"; 
        }else{ 
         $strWhere = "client like "."'%$concept%'"; 
        } 
       } 
       if($opt==2) 
        { 
        if($strWhere != ""){ 
         $strWhere = $strWhere." or client like "."'%$concept%'"; 
        }else{ 
         $strWhere = "client like "."'%$concept%'"; 
        } 
       } 
      } 
      if($thing != NULL){ 
       $opt = $this->input->get('and'); 


       if($opt==1) 
        { 
        if($strWhere != "") 
         { 
         $strWhere = $strWhere." and client like "."'%$thing%'"; 
        }else{ 
         $strWhere = "client like "."'%$thing%'"; 
        } 
       } 
       if($opt==2) 
        { 
        if($strWhere != ""){ 
         $strWhere = $strWhere." or client like "."'%$thing%'"; 
        }else{ 
         $strWhere = "client like "."'%$thing%'"; 
        } 
       } 
      } 
      if($oldid != NULL){ 
       $opt = $this->input->get('and'); 


       if($opt==1) 
        { 
        if($strWhere != "") 
         { 
         $strWhere = $strWhere." and client like "."'%$oldid%'"; 
        }else{ 
         $strWhere = "client like "."'%$oldid%'"; 
        } 
       } 
       if($opt==2) 
        { 
        if($strWhere != ""){ 
         $strWhere = $strWhere." or client like "."'%$oldid%'"; 
        }else{ 
         $strWhere = "client like "."'%$oldid%'"; 
        } 
       } 
      } 
      if($note != NULL){ 
       $opt = $this->input->get('and'); 


       if($opt==1) 
        { 
        if($strWhere != "") 
         { 
         $strWhere = $strWhere." and note like "."'%$note%'"; 
        }else{ 
         $strWhere = "note like "."'%$note%'"; 
        } 
       } 
       if($opt==2) 
        { 
        if($strWhere != ""){ 
         $strWhere = $strWhere." or note like "."'%$note%'"; 
        }else{ 
         $strWhere = "note like "."'%$note%'"; 
        } 
       } 
      } 

컨트롤러 :

public function search() 
     { 

      print_r($this->search_model->search_record()); 

      $limit = 1; 
      $config["base_url"] = base_url('Home/search'); 
      $config['total_rows'] = $this->db->count_all('tblphotomstr'); 
      $config["per_page"] = $limit; 
      $config['use_page_numbers'] = TRUE; 
      $config['page_query_string'] = TRUE; 
      $config['enable_query_strings'] = TRUE; 
      $config['cur_tag_open'] = '&nbsp;<li class="active"><a>'; 
      $config['cur_tag_close'] = '</a></li>'; 
      $config['next_link'] = 'Next'; 
      $config['prev_link'] = 'Previous'; 
      $this->pagination->initialize($config); 

      $offset = 0; 
     if (!empty($_GET['per_page'])) { 
      $pageNo = $_GET['per_page']; 
      $offset = ($pageNo - 1) * $limit; 
     } 

      $data = array(); 
      $this->db->limit($limit, $offset); 

      $data['records']= $this->search_model->search_record(); 
      print_r($data); 
      $this->template->set('title', 'Edit Record'); 
      $this->template->load('default_layout', 'contents' , 'search', $data); 

     } 
+0

PLS는 전체 모델 코드와 매김 코드를 게시 도움이되기를 바랍니다 - 내가 모두를 생각하기 때문에 get 매개 변수가 2 페이지 또는 그와 비슷한 것을 클릭 한 다음에 길을 잃는 중입니다 ... 또 다른 추천 - querybuilder를 올바르게 사용해야합니다. 전체 쿼리가 완전히 안전하지 않습니다. – sintakonte

+0

보기에서 i가 사용되었습니다 (

). 모든 요구 사항 .. 만약 가이드가 나를 안내하는 내 전체 모델 코드를 넣어 –

+0

일부 설명과 함께 양식 이미지로 @ sintakonte 내 쿼리를 업데이 트 ... 분명하지 pls 가이드 .. –

답변

0

당신은 프로파일 러를 시도 할 수 있습니다. ($ this-> output-> enable_profiler (TRUE);) 컨트롤러 구조에서 활성화하면 모든 하위 함수에서도 결과를 볼 수 있습니다. 그것은 목록 당신이 문제를 찾을 필요가 필요한 모든 데이터가 될 것입니다

(데이터를 얻을 수는 쿼리를 실행)

+0

나는 내 쿼리를 위의 업데이트 @alchalade –

+0

나는 ur query @alchalade를 사용했다 .... 나의 데이터가 아래 줄에있다. 데이터를 얻는다. $ _GET [ 'pfrom'] $ _GET [ 'pto'] $ _GET [ 'afrom'] $ _GET [ 'ato $ _GET [ 'name'] $ _GET [ 'name'] $ _GET [ 'fname'] $ _GET [ 'client'] $ _GET [ ' $ _GET [ 'id'] $ _GET [ 'old'] $ _GET [ 'note'] –