[英]How to fetch Data from another table and show on single table in PHP Codeigniter?
[英]Show data from another table with modal - Codeigniter
我的建议是:
1-向详细信息按钮添加一个类,即: detailButton
和具有especific reportCode的数据属性或href。
<table>
<tr>
<td> ... </td>
<td> <button class='detailButton' href='<?php echo $reportCode; ?>' ... </button> </td>
2-将jquery添加到页面底部:
$('.detailButton').click(function(e){
e.preventDefault();
var reportCode = $(this).attr('href');
var url = "yourUrl/controller/function";
$.post(url,{ code:reportCode },function(data){
//do stuff
//i.e: $('.modal').html(data).show();
});
});
现在,您有了一个获取reportCode的函数,并通过POST将其发送到控制器,您返回了一些内容,并且该函数获取了响应并附加到html。
注意,这种方式必须从控制器返回一个表。 您也可以进行动态构建。
希望能帮助到你!
更新:您可以检查模型中的值,然后使用一个exisitin模板(例如,一个生成明细表的模板),并作为要附加到正确位置的数据返回到视图(方法1):
function detail(){
$getcode= $this->input->post('reportCode');
$data['showdetail'] = $this->model_expreport->showdetail($getcode);
$ret = $this->load->view('detail_template',$data,true); //return as data
print_r($ret);
}
或者,您可以使用方法2:
function detail(){
$getcode= $this->input->post('reportCode');
$data['showdetail'] = $this->model_expreport->showdetail($getcode);
$this->output->set_content_type('application/json');
$this->output->set_output(json_encode($data));
}
这样,视图将获取可迭代并构建自己的页面的JSON。 或者,您可以创建完整视图并将其作为数据返回(以便仅附加到视图中)。
您可以同时使用。
在视图中,您将获得完整视图:
$.post(url,{ code:reportCode },function(data){
$('#modal').html(data); //put the 'detail' response to the modal
}
或使用JSON,您必须进行迭代并动态创建自己的div,为此有很多教程: https : //uno-de-piera.com/cargar-json-con-jquery-y-codeigniter/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.