2014-12-24 58 views
0

添加這裏是我的模型invoice.php行表中的每個搜索後,笨

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class invoice extends CI_Model{ 

    function __construct(){ 
     parent::__construct(); 
    } 

    public function search($keyword){ 
     $this->db->like('code',$keyword); 
     $query = $this->db->get('products'); 
     return $query->result(); 
    } 
} 

和我的控制器的search.php

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 
class search extends CI_Controller{ 

    function __construct(){ 
     parent:: __construct(); 
     $this->load->model('frontend/invoice'); 
     $this->load->helper(array('form', 'url','html')); 
    } 

    public function index(){ 
     $keyword = $this->input->post('keyword'); 
     $data['results'] = $this->invoice->search($keyword); 
     $this->load->view('header'); 
     $this->load->view('frontend/navafterlogin'); 
     $this->load->view('frontend/dashboard'); 
     $this->load->view('frontend/results_view',$data); 
     //$this->load->view('frontend/invoicetable'); 
     $this->load->view('footer'); 
    } 

} 

和呼應搜索結果results_view.php視圖

<table> 
<?php 
foreach($results as $row){ ?> 
    <tr> 
     <td><input type="text" value="<?php echo $row->name?>"/></td> 
     <td><input type="text" id="rate" value="<?php echo $row->perunitprice?>"/></td> 
     <td><input type="number" id="quantity"value="" placeholder="quantity"/></td> 
     <td><input type="number" id="result" value="" placeholder="total"/></td> 
    </tr> 
<?php 
} 
?> 
</table> 

,並從那裏我搜索dashboard.php

我的表格
<div class="row"> 
     <?php echo form_open('frontend/search');?> 
      <div class="col-sm-2"> 
       <input type="text" class="form-control" name="keyword" placeholder="productcode"> 
      </div> 

     <div class="col-sm-2"> 
      <button class="btn btn-warning">Find</button> 
     </div> 
    </div> 

我想要的是每當我執行搜索時,我想在我的表上添加新行,這是result_view在這種情況下,並在單獨的行中回顯結果。目前,我只能搜索一次,然後第二次搜索,第一結果得到由第二個代替,我不希望它發生

回答

0

你有沒有嘗試過使用「會話」,如果沒有,嘗試了這一點在你的控制器指數函數:

public function index(){ 
    $this->load->library('session'); 
    $keyword = $this->input->post('keyword'); 
    $result = $this->invoice->search($keyword); 
    $search = $this->session->userdata('search') ? (array)$this->session->userdata('search') : array(); 
    array_push($search, $result); 
    $this->session->set_userdata('search', $search); 
    $data['results'] = $search; 

    $this->load->view('header'); 
    $this->load->view('frontend/navafterlogin'); 
    $this->load->view('frontend/dashboard'); 
    $this->load->view('frontend/results_view',$data); 
    //$this->load->view('frontend/invoicetable'); 
    $this->load->view('footer'); 
} 
相關問題