2016-11-09 18 views
2

當我點擊'購買清單'中的'發票號'時,我需要打開一個可摺疊的表,產品列表匹配沒有 我使用jQuery來開闢一個可摺疊的桌子和Ajax檢索數據Codeigniter-Ajax我需要返回多個行,以及如何在我的視圖文件中訪問它

我認爲文件中的發票:我使用AJAX來檢索數據

<script> 
$(document).ready(function(){ 
$(".listproduct".click(function(){ 
    var value = $(this).text(); 
$.ajax({ 
     type:'POST', 
     url:'<?=site_url("purchasecont/getproductlist"; ?>', 
     data: {'data' : value} , 
     success:function(result){ 

       $('#invoiceno').html(result['invoiceno']); 
       $('#productname').text(result['productname']); 
       $('#price').text(result['price']); 


     } 
    }); 
$(".collapse".collapse('toggle'); 

}); 
}); 
</script> 

MY控制器的文件:我將從表中檢索多於一行

public function getproductlist(){ 
//check if is an ajax request 
if($this->input->is_ajax_request()){ 
    //checks if the variable data exists on the posted data 
    if($this->input->post('data')){ 

     //query in your model you should verify if the data passed is legit before querying 
     $data = $this->purchasemod->getproductlist($this->input->post('data')); 
     $this->output->set_content_type('application/json'); 
     $this->output->set_output(json_encode($data)); 
     return $data; 
       } 
} 
} 

MY模型文件:我會從表

public function getproductlist($q){ 
    $this->db->select('*');  
    $this->db->from('purchaseprolist'); 
    $this->db->where('purchaseprolist.invoice' , $q); 
    $this->db->where('purchaseprolist.price != ',0,FALSE); 
    $query = $this->db->get(); 
foreach ($query->result() as $row) 
    { 
    return $row; 
    } 

    } 
+0

好心幫我!我有一個錯誤 –

回答

0

return $row;被檢索多行一個循環內將只返回一行。

相反的:

foreach ($query->result() as $row) 
{ 
    return $row; 
} 

只要做到:

return $query->result(); 
相關問題