2016-11-20 9 views
0

PHPとCの新機能です。検索フィルタを作成しています。次のページネーションリンクに移動するまでフィルタは正常に動作しています。私が最初のリンクにいるとき、データはフィルター/検索キーワードに従って表示されますが、次のリンクに移動するとすべてが消えます(すべてのデータがページに表示されます)。 私は多くを検索し、多くのリンク/チュートリアルを通過しましたが、そのような問題に対して本物の/適切な/特定の答えが見つかりませんでした。 ここではLinkがStack Overflowで見つけられていますが、LUCKはありません。Codeigniterのページネーションで検索フィルタが正しく動作しません

私のコントローラコード:

public function URecords() { 
    $config = array(); 
    $keyword = $this->input->post('search'); 
    $this->session->set_flashdata('search',$keyword); 
    $config["base_url"] = base_url() . "master/URecords"; 
    $config["total_rows"] = $this->bm->record_count($keyword); 
    $config['use_page_numbers'] =FALSE; 
    $config['cur_tag_open'] = '<a><b class="text-success">'; 
    $config['cur_tag_close'] = '</b></a>'; 
    $config["per_page"] =4; 
    $config["uri_segment"] = 3; 

    $this->pagination->initialize($config); 

    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0; 
    $data["posts"] = $this->bm->fetch_countries($config["per_page"], $page,$keyword); 

    $data["links"] = $this->pagination->create_links(); 
    $this->load->view('Admin/header'); 
    $this->load->view('Admin/nav'); 
    $this->load->view('Admin/sidebar'); 
    $this->load->view('Admin/userrecord', $data); 
    $this->load->view('Admin/footer'); 
} 

私のモデルのコード:

public function record_count($keyword) { 
     $this->db->like('Employee_Name',$keyword); 

     $this->db->from('dc_user'); 
     return $this->db->count_all_results(); 

     // return $this->db->count_all("dc_user"); 
    } 

    public function fetch_countries($limit, $start,$keyword) { 
     $this->db->limit($limit, $start); 
     $this->db->like('Employee_Name',$keyword); 
     $query = $this->db->get_where("dc_user"); 
     if(empty($query->result())) 
     { 
      //echo "No record found in data base"; 
      $this->session->set_flashdata('msg', '<div class="alert alert-success text-center">No Record Found!</div>'); 
     } 
     if ($query->num_rows() > 0) { 
      foreach ($query->result() as $row) { 
       $data[] = $row; 
      } 
      return $data; 
     } 
     return false; 
    } 

マイビューコード:

<div class="right_col" role="main"> 
      <div class=""> 
       <div class="page-title"> 

        <div class="title_right"> 
         <div class="col-md-5 col-sm-5 col-xs-12 form-group pull-right top_search"> 
          <form action="<?php echo base_url();?>Master/URecords" method="post"> 
          <div class="input-group"> 
           <input type="text" class="form-control" id="search" name="search" value="<?php if(isset($_SESSION['search'])){echo $_SESSION['search'];}?>" placeholder="Search for..."> 
        <span class="input-group-btn"> 
         <input class="btn btn-default" type="submit" name="submit" id="submit" value="GO!"> 

        </span> 
          </div> 
          </form> 
         </div> 
        </div> 
       </div> 

       <div class="clearfix"></div> 

       <div class="row"> 



        <div class="col-md-12 col-sm-12 col-xs-12"> 
         <div class="x_panel"> 
          <div class="x_title"> 
           <h2>All User's Record</h2> 
           <ul class="nav navbar-right panel_toolbox"> 
            <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a> 
            </li> 
            <li class="dropdown"> 
             <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a> 
             <ul class="dropdown-menu" role="menu"> 
              <li><a href="#">Settings 1</a> 
              </li> 
              <li><a href="#">Settings 2</a> 
              </li> 
             </ul> 
            </li> 
            <li><a class="close-link"><i class="fa fa-close"></i></a> 
            </li> 
           </ul> 
           <div class="clearfix"></div> 
          </div> 


          <div class="x_content"> 
           <div class="table-responsive"> 
            <?php if(isset($_SESSION['msg'])){?> 
            <span class="text-info col-md-6 col-sm-6 col-xs-12 col-md-offset-3"> 
          <?php echo $this->session->flashdata('msg'); ?> 
          </span> 
            <?php } else {?> 
            <table class="table table-striped jambo_table bulk_action"> 
             <thead> 
             <tr class="headings"> 

              <th class="column-title">Employee Name </th> 
              <th class="column-title">Email </th> 
              <th class="column-title">Contact # </th> 
              <th class="column-title">Date Of Birth </th> 
              <th class="column-title">Designation </th> 
              <th class="column-title">Profile Picture </th> 


             </tr> 
             </thead> 

             <tbody> 
             <?php foreach($posts as $post) { ?> 
              <tr class="even pointer"> 
               <td class=" "><?php echo $post->Employee_Name; ?></td> 
               <td class=" "><span class="text-info"><?php echo $post->Email; ?></span></td> 
               <td class=" "><?php echo $post->Contact; ?></td> 
               <td class=" "><?php echo $post->DOB; ?></td> 
               <td class=" "><?php echo $post->Designation; ?></td> 
               <td class=" "><img src="<?php echo base_url();?>profileimages/<?php echo $post->Profile_Image; ?>" alt="..." class="img-square profile_img" style="width: 200px !important; height: 100px !important;"> </td> 
               </td> 
              </tr> 
             <?php } ?> 




             </tbody> 
            </table> 

            <div class="text-center"><nav aria-label="Page navigation"> 
              <ul class="pagination"> 

               <li><?php echo $links; ?></li> 

              </ul> 
             </nav></div> 

<?php }?> 
           </div> 
          </div> 
         </div> 
        </div> 
       </div> 
      </div> 
     </div> 

主題:

問題は:検索フィールドにキーワードを入力すると、最初は正しい結果が表示されますが、他のページングリンクに移動すると検索結果が失われます。私は、ページネーションリンクを介して行くとき

は、それはそれとして、作品が検索のスタートに動作します:私が欲しいもの

+0

あなたの問題を示す最小の例にそれをizeしてください。 – amik

答えて

1

ページネーションリンクをナビゲートするときにキーワードを取得できないという問題があります。これで

$keyword = $this->input->post('search'); 
$this->session->set_flashdata('search',$keyword); 

$keyword = $this->input->post('search'); 
if ($keyword === null) $keyword = $this->session->userdata('search'); 
else $this->session->set_userdata('search',$keyword); 

このコードセッションにキーワードを保存し、チェック
改ページは、通常の<a>ので、それは

この行を置き換える任意のPOSTデータを送信していないですPOSTによってキーワードが提供されていない場合は、セッションからキーワードを取得してください。

関連する問題