Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter Ajax我需要返回多行,以及如何在视图文件中访问它_Php_Ajax_Codeigniter - Fatal编程技术网

Php Codeigniter Ajax我需要返回多行,以及如何在视图文件中访问它

Php Codeigniter Ajax我需要返回多行,以及如何在视图文件中访问它,php,ajax,codeigniter,Php,Ajax,Codeigniter,当我点击“采购清单”中的“发票号”时,我需要打开一个可折叠的表格,列出与发票号匹配的产品清单 我使用jquery打开一个可折叠的表,使用Ajax检索数据 我的视图文件:我正在使用AJAX检索数据 <script> $(document).ready(function(){ $(".listproduct".click(function(){ var value = $(this).text(); $.ajax({ type:'POST', ur

当我点击“采购清单”中的“发票号”时,我需要打开一个可折叠的表格,列出与发票号匹配的产品清单 我使用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;
  }

  }

返回$row将只返回一行

而不是:

foreach ($query->result() as $row)
{
    return $row;
}
只要做:

return $query->result();

请帮帮我!我有一个错误