我循环循环并且有错误。 我之前试过这个,但现在它不起作用。
我的错误是:
遇到PHP错误
严重性:注意
消息:未初始化的字符串偏移量:0
文件名:views / 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-marikina \ index.php行:292功能: require_once
遇到PHP错误
严重性:警告
消息:非法字符串偏移'user_id'
文件名:views / 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-marikina \ 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 */
答案 0 :(得分:3)
你们每个人都很奇怪:
foreach($users as $users){
$id =$users['user_id'];
....
不应该更像:
foreach($users as $user){
$id =$user['user_id'];
.....
我确定迭代并分配给相同的变量名称可能会导致意外的数组。
答案 1 :(得分:3)
你得到这个未初始化的字符串偏移通知,因为你的foreach值,你不能使用相同的变量名称值,否则它将被视为覆盖。
更改这些:
foreach($view as $view_value){
$audit_id = $view_value['audit_id'];
.......
}
foreach($users as $user_value){
$id = $user_value['user_id'];
.....
}