我想每天在Codeigniter中自动更新年龄列。我尝试以下方法,但已正确更新。 在控制器中
$member_id = $this->cron->get_member_id();
if(!empty($member_id))
{
foreach($member_id as $id)
{
$dob = $id['DOB'];
$today = date("Y-m-d");
$diff = date_diff(date_create($dob), date_create($today));
$age = $diff->format('%y');
$this->cron->change_age($id['Memberid'],$age);
}
}
模型
public function get_member_id()
{
$this->db->select('*');
$this->db->from('registration');
$query = $this->db->get();
return $query->result_array();
}
public function change_age($id,$age)
{
$data = array(
'Age' => $age
);
$this->db->where('Memberid',$id);
$this->db->update('registration',$data);
}
请帮助解决。