【发布时间】:2021-11-27 13:05:44
【问题描述】:
目前我正在使用 Mysql 和 CodeIgniters MVC 框架来填写我的数据。该表记录了已进行的每个状态更改以及更改时间。这是数据库当前的样子:
我在名为 status_from 和 status_to 的表中添加了新列,我希望这些列从 action 列中获取子字符串。
但是现在我如何使用以下代码在我的数据库中显示它:
控制器类:
public function status($status){
$statusar = array('D'=>'Draft','N'=>'Unpublish','Y'=>'Publish','U'=>'Action','L'=>'Unlisted','S'=>'Sold','T'=>'Let');
if($this->input->post('id')){
foreach($this->input->post('id') as $key => $id):
$check = $this->listings_model->loadlisting_check($id);
$log = "Listing website status changed from ". $statusar[$check->status]." to ".$statusar[$status].". The listing ID is #".$id.".";
$this->logs_model->insert_log(array('refno'=>$check->refno,'action'=>trim($log)));
$data=array('status'=>$status);
if($status == 'T' || $status == 'Y' || $status == 'S'){
$pub = 1;
}else{
$pub =0;
}
$this->listings_model->lpupdate(array('property_publish'=>$pub),$id);
endforeach;
}
return true;
}
listings_model:
function loadlisting_check($id)
{
$this->db->select("refno, status, archive");
$id=$this->db->escape_str($id);
$cond=array("$this->table_name.$this->primary_key"=>$id);
$this->db->where($cond);
$this->db->from($this->table_name);
$query = $this->db->get();
return $query->row();
}
logs_model:
public function insert_log($log)
{
$log['agent_id'] = $this->session->userdata('clientsessuserid');
$log['logtime'] = date('Y-m-d H:i:s');
$this->db->insert($this->table_name, $log);
return true;
}
基本上我想在创建每个新条目时用 $statusar[$check->status] 填充我的 status_from 列,并用 $statusar[$status] 填充 status_to 列
【问题讨论】:
标签: php mysql codeigniter