I loop in a loop and there are errors. I tried this before but now it doesn't work.
My errors are:
A PHP Error was encountered
Severity: Notice
Message: Uninitialized string offset: 0
Filename: views/audit_trail_view.php
Line Number: 36
Backtrace:
File: C:\xampp\htdocs\cemo-marikina\application\views\audit_trail_view.php Line: 36 Function: _error_handler
File: C:\xampp\htdocs\cemo-marikina\application\controllers\Employee.php Line: 2819 Function: view
File: C:\xampp\htdocs\cemo-marikina\index.php Line: 292 Function: require_once
A PHP Error was encountered
Severity: Warning
Message: Illegal string offset 'user_id'
Filename: views/audit_trail_view.php
Line Number: 36
Backtrace:
File: C:\xampp\htdocs\cemo-marikina\application\views\audit_trail_view.php Line: 36 Function: _error_handler
File: C:\xampp\htdocs\cemo-marikina\application\controllers\Employee.php Line: 2819 Function: view
File: C:\xampp\htdocs\cemo-marikina\index.php Line: 292 Function: require_once
Views: audit_trail_view.php
<?php
$first_name='';
$last_name='';
$middle_name='';
$separator="";
$user_id="";
?>
<table border ="1" width="75%" >
<tr>
<td>User</td>
<td>Action</td>
<td>Date</td>
</tr>
<?php
foreach($view as $view){
$audit_id= $view['audit_id'];
$audit_user_id= $view['audit_user_id'];
$audit_record= $view['audit_record'];
$audit_new_record= $view['audit_new_record'];
$audit_date= $view['audit_date'];
$timestamp=strtotime($view['audit_date']);
$year=date('Y', $timestamp);
$month=date('M', $timestamp);
$day=date('d', $timestamp);
$hour=date('h', $timestamp);
$minute=date('i', $timestamp);
$ap=date('a', $timestamp);
foreach($users as $users){
$id =$users['user_id'];
if($id==$audit_id){
$first_name=$users['fname'];
$last_name=$users['lname'];
$middle_name=$users['mname'];
}
else{
$first_name='';
$last_name='';
$middle_name='';
}
}
?>
<tr>
<td><?php echo $last_name." ".$first_name.", ".$middle_name;?> </td>
<td><?php echo$audit_record.$separator.$audit_new_record;?> </td>
<td><?php echo$month." ".$day.", ".$year." ".$hour.":".$minute." ".$ap;?> </td>
</tr>
<?php
}
?>
</table>
Controller:Employee.php
public function audit_trail_view(){
$data['view']=$this->emp_model->audit_trail_view();
$data['users']=$this->emp_model->audit_trail_users();
$this->load->view("audit_trail_view.php",$data);
}
Model: Emp_model.php
/* AUDIT TRAIL VIEW START*/
function audit_trail_view(){
$this->db->select('*');
$this->db->from('audit_table');
$query = $this->db->get();
return $query->result_array();
}
function audit_trail_users(){
$this->db->select('*');
$this->db->from('users');
$query = $this->db->get();
return $query->result_array();
}
/* AUDIT TRAIL VIEW END*/
/* AUDIT TRAIL START */
function audit_trail(){
$data=array(
'audit_user_id'=>$this->input->post('audit_user_id'),
'audit_record'=>$this->input->post('audit_record'),
'audit_new_record'=>$this->input->post('audit_new_record'),
);
$this->db->insert('audit_table',$data);
}
/* AUDIT TRAIL END */