我循環並出現錯誤。 我以前嘗試過,但現在不起作用。codeigniter - 未初始化的字符串偏移量:0和非法字符串偏移量
我的錯誤是:
一個PHP錯誤遇到
嚴重性:注意
消息:未初始化字符串偏移量:0
文件名:觀點/ audit_trail_view。 php
行號:36
回溯:
文件: C:\ XAMPP \ htdocs中\ CEMO,馬裏基納\程序\意見\ audit_trail_view.php 行:36功能:_error_handler
文件: C:\ XAMPP \ htdocs中\ CEMO-馬裏基納\應用\控制器\ Employee.php 線:2819功能:視圖
文件:C:\ XAMPP \ htdocs中\ CEMO-馬裏基納\的index.php線:292功能: require_once
甲PHP錯誤遇到
嚴重性:警告
消息:非法串偏移 'USER_ID'
文件名:視圖/ audit_trail_view.php
行號:36
回溯:
文件: C:\ XAMPP \ htdocs中\ CEMO-馬裏基納\應用\視圖\ audit_trail_view.php 行:36功能:_error_handler
文件: C:\ XAMPP \ htdocs中\ CEMO-馬裏基納\應用\控制器\ Employee.php 線:2819功能:視圖
文件:C:\ XAMPP \ htdocs中\ CEMO-馬裏基納\的index.php線:292功能: require_once
瀏覽: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>
控制器: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);
}
型號: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 */
是什麼線路36 –
的$ id = $用戶[ 'user_ID的']; - @Abdulla – Rochelle