我创建一个php脚本来检查更新前的值。这个脚本运行正常。但是,我想知道如何简化这一点。如果要检查数百个列,则它会生成数百个php行。
public function edit_project_master(){
$no_pro = 'PRJ-2017-501'; //
$na_pro = $this->input->post('na_pro'); //value for edit
$ja_pro = $this->input->post('i_metode'); //value for edit
$check_pro = $this->MProject->get_det_pro($no_pro); //get data form table
//checking script
foreach($check_pro as $res_check_pro){
if($na_pro != $res_check_pro['NAMA_PROJECT']){ //IF VALUE DIFFERENT
$col_name;
foreach($res_check_pro as $key_pro => $val_pro){
if($res_check_pro['NAMA_PROJECT'] == $val_pro){
$col_name = $key_pro; //GET COLUMN NAME
}
}
$data['ACTIVITY'] = "UPDATE";
$data['OLD_VALUE'] = $res_check_pro['NAMA_PROJECT'];
$data['NEW_VALUE'] = $na_pro;
$data['COL_AFFECTED'] = $col_name;
$data['TABLE_AFFECTED'] = "PM_REQUIREMENT_PROJECT"; //How to get table name automatically??
$data['ANNOTATION'] = NULL;
$data['EXECUTOR'] = $this->session->userdata('nip');
$data['CHANGED_ON'] = date("Y-m-d H:i:s");
$data['CHANGED_BY'] = $_SERVER['REMOTE_ADDR'];
$data['STATUS'] = 1;
$this->MProject->ins_system_log($data);
}
if($ja_pro != $res_check_pro['JADWAL_PROJECT']){
$col_name;
foreach($res_check_pro as $key_pro => $val_pro){
if($res_check_pro['JADWAL_PROJECT'] == $val_pro){
$col_name = $key_pro;
}
}
$data['ACTIVITY'] = "UPDATE";
$data['OLD_VALUE'] = $res_check_pro['JADWAL_PROJECT'];
$data['NEW_VALUE'] = $na_pro;
$data['COL_AFFECTED'] = $col_name;
$data['TABLE_AFFECTED'] = "PM_REQUIREMENT_PROJECT"; //How to get table name automatically??
$data['ANNOTATION'] = NULL;
$data['EXECUTOR'] = $this->session->userdata('nip');
$data['CHANGED_ON'] = date("Y-m-d H:i:s");
$data['CHANGED_BY'] = $_SERVER['REMOTE_ADDR'];
$data['STATUS'] = 1;
$this->MProject->ins_system_log($data);
}
}
}
这用于保存日志文件以进行更新。因此,如果更新数据,则会将日志存储在表中。