![](/img/trans.png)
[英]Codeigniter: How to upload more than one file (not input[] array) and return current path to the file
[英]Codeigniter-Ajax i need to return more than one rows and how to access it in my view file
當我在“購買清單”中單擊“發票編號”時,我將需要打開一個可折疊表格,該表格將列出與發票匹配的產品列表,否,我正在使用jquery打開可折疊表格,並使用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>
我的控制器文件:我將從表中檢索多個行
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;
}
}
}
我的模型文件:我將從表中檢索多個行
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;
}
}
return $row;
循環內部將僅返回一行。
代替:
foreach ($query->result() as $row)
{
return $row;
}
做就是了:
return $query->result();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.