2016-02-25 32 views
0

我是codeigniter中的新手。我正在試圖在搜索框下創建一個產品信息表,根據每個產品型號搜索,表格行將從數據庫中動態增加。現在之前的搜索數據被新的搜索結果所取代,並且只顯示一個產品數據,但我想在表格行中顯示所有先前的搜索結果。我通過使用會話嘗試了它,但未運行。謝謝你的幫助。想要在codeigniter中的動態表格行

Model: 
class Product_Model extends CI_Model { 


    function product_search($model) 
    { 

     $this->db->like('modelno',$model); 
     $query = $this->db->get('alliteam'); 



     if($query->num_rows() > 0){ 

     foreach ($query->result() as $row) 
     { 
     $data[] = $row; 
     } 
     return $data; 
    } 


    } 
} 


Controller: 

public function sell(){ 
     $this->load->library('session'); 
       $data = array(
      'title' => 'New Customer', 
      'action' => site_url('Product/sell'), 
      'button' => 'Add Item' 
     ); 

     $model = $this->input->post('model',TRUE); 

     $data['productinfo'] = $this->Product_Model->product_search($model); 



    $this->session->set_userdata($productinfo); 

    $this->load->view('customer',$this->session->all_userdata()); 



     } 

查看

<form action="<?php echo $action;?>" method="post"> 
        <fieldset> 
        <div class="control-group"> 

         <label class="control-label" >Model No :</label> 
         <div > 
          <input type="text" name="model" value="" > 
          <span> Enter a product model no</span> 
         </div> 

        <div class="form-actions"> 

         <input type="submit" name="add_item" value="<?php echo $button;?>"/> 

        </div> 
        </fieldset> 
    </form> 



       <table > 
        <thead> 
         <tr> 
          <th>Name</th> 
          <th>Model Number</th> 
          <th>Description</th> 

         </tr> 
        </thead> 
        <tbody> 


        <?php 
        if($this->input->post('add_item')){ 
        foreach($productinfo as $product):?> 
        <tr> 

         <td class="center"><?php echo $product->name ?></td><br>         
         <td class="center"><?php echo $product->modelno ?></td> 
         <td class="center"><?php echo $product->product_description?></td> 
       </tr> 
        <?php endforeach; } ?> 
        </tbody> 
       </table>    

回答

0

你不需要在這裏使用的會話。

編輯控制器

public function sell(){ 
    $data = array(
      'title' => 'New Customer', 
      'action' => site_url('Product/sell'), 
      'button' => 'Add Item' 
     ); 

     $model = $this->input->post('model',TRUE); 

     $data['productinfo'] = $this->Product_Model->product_search($model); 



    $this->load->view('customer',$data); 



     } 
+0

對不起同以前的結果。不按我想要的那樣工作。 – ttA01