I have table in sales activity log like below
sales activity
id | activity | userid | companyid | dateadded
1 Set Meeting 3pm 2 1 2019-12-26 10:29:59
2 Send Proposal 2 1 2019-12-27 11:15:04
3 Meeting 3 2 2019-12-27 13:01:13
I want to show activity log based on client name with modal popup, but the result is undefined.
Here's the code for js
<script type="text/javascript">
$('a[href="#myHistory"]').on('click',function(){
var id = $(this).attr('id');
$.ajax({
type : "POST",
url : "<?php echo admin_url(). 'sales/get_history'; ?>",
data : {id:id},
success : function(data){
var html = '';
var i;
for(i=0; i<data.length; i++){
html += '<tr>'+
'<td>'+data[i].description+'</td>'+
'<td>'+data[i].dateadded+'</td>'+
'</tr>';
}
$('#show_data').html(html);
}
})
})
</script>
Here's my controller
public function get_history(){
$code=$this->input->post('id');
$data=$this->sales_model->get_history_by_code($code);
echo json_encode($data);
}
Here's my model
function get_history_by_code($code)
{
$abc=$this->db->query("SELECT * FROM tblsales_log WHERE companyid='$code'");
if($abc->num_rows()>0){
foreach ($abc->result() as $data) {
$result=array(
'description' => $data->description,
'dateadded' => $data->dateadded,
);
}
}
return $result;
}
Here's my view
<div class="modal" id="myHistory" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<table id="example" class="table table-striped table-bordered dt-responsive nowrap" style="width:100%">
<thead>
<tr>
<th>Description</th>
<th>Added Time</th>
</tr>
</thead>
<tbody id="show_data">
</tbody>
</table>
</div>
</div>
</div>
When the modal popup, it's only show undefined. I have tried console.log, but the result is still undefined. Do you know where's the error of my code ?
Thank you