2017-11-19 5 views
0

入力データに基づいてデータベースからフォームにデータを取り出しています。
例:フォームで、私が姓を検索すると、姓のデータを取得する必要があります。 ANDまたはOR演算子ボタンを使用してすべてのフィールド検索が成功しました。次のレコードの検索でデータを取り出して、空のフィールドを表示しているレコードに最初のレコードが表示されません。

しかし、1つのレコードだけを取得しているにもかかわらず、検索基準ごとに別のレコードを取得していないページネーションには問題があります。

ここでは、ページを含めるためにテンプレートライブラリを使用しています。ここでは上記のフォームの画像で

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

ビューで使用した(

)。私はレコードの検索のための私のモデル全体のコードを置く..pls私のガイド任意の要件..投稿 –

+0

私はいくつかの説明とフォームイメージと@ sintakonteを更新...もしplsガイドをクリアしない場合.. –

答えて

0

あなたはプロファイラを試すことができます。 ($ this-> output-> enable_profiler(TRUE);)コントローラ構造体で有効にすると、各サブ関数の結果も表示されます。

それはあなたの問題を見つけるために必要なすべての必要なデータリストになります(データを取得し、クエリを実行)

はそれが

+0

私は上記のクエリを更新@alchalade –

+0

私はurクエリを使用しました@alchalade ....私の取得データは以下の行になっています... $ _GET ['pfrom'] $ _GET ['pto'] $ _GET ['afrom'] $ _GET ['ato $ _GET ['name'] $ _GET ['name'] $ _GET ['fname'] $ _GET ['client'] $ _GET [' $ _GET ['id'] $ _GET ['old'] $ _GET ['note'] –

関連する問題