2014-01-30 162 views
0

我遇到的搜索功能與分頁問題笨搜索

這裏有點問題分頁的代碼

控制器:

if(isset($_POST['search'])) 
      { 
       $data['item'] = mysql_real_escape_string($this->input->post('search')); 
       $this->session->set_userdata('item', $data['item']); 
      } else { 
       $data['item'] = $this->session->userdata('item'); 
      } 

      $page=$this->uri->segment(3); 
      $limit=16; 
      if(!$page): 
      $offset = 0; 
      else: 
      $offset = $page; 
      endif; 
      //$data['barang'] = $this->input->post('search'); 
      $data['search'] = $this->main_model->search($data['branchid'],$data['item'],$offset,$limit); 
      $total_search = $this->main_model->total_search($data['branchid'],$data['item'],$offset,$limit); 
      $config['base_url'] = base_url() . 'product/search/'; 
      $config['total_rows'] = $total_search->num_rows(); 
      $config['per_page'] = $limit; 
      $config['uri_segment'] = 3; 
      $config['first_link'] = 'First'; 
      $config['last_link'] = 'Last'; 
      $config['next_link'] = '>>'; 
      $config['prev_link'] = '<<'; 
      $config['use_page_numbers'] = TRUE; 
      $this->pagination->initialize($config); 
      $data['paginator'] =$this->pagination->create_links(); 

的觀點:

<div id="wrap"> 
     <div id="main"> 
      <a href="<?= base_url();?>dashboard" style="text-decoration:none; font-size:10px; color:black;"> HOME</a> > <a style="text-decoration:none; font-size:10px; color:black; text-transform:uppercase"> SEARCH</a> > <a style="text-decoration:none; font-size:10px; color:black; text-transform:uppercase"> <?= $barang ;?></a> 
      <br><br> 
      <?php if(!$search->result_array()): 
       echo "bla bla.<br><br>"; 
       else: 
      ?> 
      <?php foreach ($search->result_array() as $c) : ?> 
      <ul class="wipproducts"> 
      <li> 
       <?php $img_str=$c['g']?> 
       <div style="height: 25px;"> 
       <a style="text-decoration:none; color:black;" href="<?php echo base_url();?>product/detail/<?php echo $c['a']?>"><h3><?php echo $c['n']; ?></h3></a> 
       </div> 
       <?php 

       if (empty($img_str)) 
        { 
         echo "<img src='".base_url()."assets/image/image_kosong.jpg' width='100' height='100'>"; 
        } 
        else 
        { 
         echo '<a><img src="data:../../assets/image/jpg;base64,'.$img_str.'" width="100" height="100" alt="" /></a>'; 
        } 
       ?> 
       </br> 
       <small><b><?php 

       if($upcountry == 0) 
       { 

        if($c['price'] > $c['price2']) 
        { 
        echo 'IDR', ' ', '<a style="text-decoration:line-through; color:red;">',number_format($c['price'],0,",","."),'</a>','</br>'; 
        echo 'IDR', ' ',number_format($c['price2'], 0, ",", "."); 
        } 
        else 
        { 
        echo 'IDR', ' ',number_format($c['price2'], 0, ",", "."); 
        } 
       } 
       else if ($upcountry == 1) 
       { 
        { 
         if($c['price'] > $c['UNITPRICEUC']) 
         { 
         echo 'IDR', ' ', '<a style="text-decoration:line-through; color:red;">',number_format($c['price'],0,",","."),'</a>','</br>'; 
         echo 'IDR', ' ',number_format($c['UNITPRICEUC'], 0, ",", "."); 
         } 
         else 
         { 
         echo 'IDR', ' ',number_format($c['UNITPRICEUC'], 0, ",", "."); 
         } 
        } 
       } 
       else if($upcountry == 2) 
       { 
         if($c['price'] > $c['UNITPRICEFUC']) 
         { 
         echo 'IDR', ' ', '<a style="text-decoration:line-through; color:red;">',number_format($c['price'],0,",","."),'</a>','</br>'; 
         echo 'IDR', ' ',number_format($c['UNITPRICEFUC'], 0, ",", "."); 
         } 
         else 
         { 
         echo 'IDR', ' ',number_format($c['UNITPRICEFUC'], 0, ",", "."); 
         } 

       } 
       ?></b></small> 
       <small> 
       <?php 
        if($c['STOK']==0) 
        { 
         echo '<a style="color:red; font-size:12;">','Out Of Stock','</a>'; 
        } 
        else 
        { 
         echo 'Available'; 
        } 

       ?> 
       </small> 

       <?php echo form_open('cart/add'); ?> 
        <fieldset> 

         <?php 
           if($c['STOK']==0) 
           { 
            echo ''; 
           } 
           else 
           { 
            echo '<label>Quantity</label>'; 
            echo form_input('quantity', '1', 'maxlength="5"'); 
           } 

          ?> 


         <?php echo form_hidden('id', $c['a']); ?> 
         <?php echo form_hidden('color',$c['color']);?> 
          <?php 
            if($c['STOK']==0) 
            { 
             echo ''; 

            } 
            else 
            { 
             echo '<button type="submit" class="button_product" <?php echo form_submit(); ?> Add</button>'; 
            } 

           ?> 


        </fieldset> 
       <?php echo form_close(); ?> 
       </li> 
      </ul> 
      <?php 
      endforeach; 
      endif; 
      ?> 
      <br/> 
       <div id="tnt_pagination"> 
        <span class="pagination clearfix"><a><?php echo $paginator; ?></span></a> 
       </div> 
      <br> 
     </div> 
    </div> 
    <br> 

從模型查詢工作正常, 和視圖也返回查詢。 但分頁不會出現。 有什麼建議嗎?


編輯,我發現了這個問題。 似乎問題與查詢,因爲 我把極限$偏移量,$極限 在查詢結束。 和我定義$偏移爲$頁= $這個 - > URI->段(3)


FIXED

+0

的輸出是什麼''total_search-> num_rows()'也請發佈你的html代碼 –

+0

在發送前查看'$ this-> pagination-> create_links()'的輸出。 –

+0

@Nouphal.M它返回變量的行數。在這種情況下,它返回16 – mabbs

回答

0

校驗庫被正確或不加載, $this->load->library('pagination');

+0

這不能提供問題的答案。要批評或要求作者澄清,在他們的帖子下留下評論 - 你總是可以評論你自己的帖子,一旦你有足夠的[聲譽](http://stackoverflow.com/help/whats-reputation),你會能夠[評論任何帖子](http://stackoverflow.com/help/privileges/comment)。 –

+0

這不會提供問題的答案。要批評或要求作者澄清,在他們的帖子下留下評論 - 你總是可以評論你自己的帖子,一旦你有足夠的[聲譽](http://stackoverflow.com/help/whats-reputation),你會能夠[評論任何帖子](http://stackoverflow.com/help/privileges/comment)。 –

+0

它是自動安裝的。 – mabbs