I just want to fetch data from database dynamically so I've used onclick ajax method to fetch data from database without reloading.. Also I want to display it in a Modal CSS..
<td><a style="cursor:pointer;" data-toggle="modal" data-target="#myModal" onclick="get_report(<?php echo $det->user_id; ?>);">Today Report</a>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Today Report</h4>
</div>
<div class="modal-body">
<div id="rep_id"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</td>
At the Bottom,
function get_report(sales_id)
{
$.ajax({
url: "<?php echo base_url()."Sales_exec/get_report/"; ?>",
method: "post",
data : { sales_id : sales_id }
}).done(function(response){
$('.modal-body').html(response);
});
}
</script>
In my controller,
public function get_report()
{
$sales_id = $this->input->post('sales_id');
$response = $this->Sales_exec_model->today_sales_report($sales_id);
}
And my model is,
public function today_sales_report($id)
{
$query = $this->db->query('SELECT * FROM tbl_reports WHERE sales_id="'.$id.'" AND DATE(created) = CURDATE()');
if ($query->num_rows() == 1)
{
$report['rep']= $query->row();
print_r($report);die;
}
}
And I'm getting output in the body of the modal as:
Array ( [rep] => stdClass Object ( [rep_id] => 3 [client_name] => joyner [address] => client_address [area] => client_area [sales_id] => 1 [sales_head_id] => 85 [comment] => 0 [pay_by] => cash [amt_value] => 1.00 [created] => 2016-12-22 ) )
Can anyone help me to get these data separated from array to display it?