我无法通过Codeigniter(PHP(、中的数组更新数据
当列premium_count
减少到0 时,我想更新或设置列premium_id
和溢价为0
控制器功能:-
$premium_count = !empty($logged_user[0]->premium_count) ? $logged_user[0]->premium_count : '0';
if($premium_count == '0') {
$data = array(
'premium_count' => '0',
'premium_id' => '0',
'premium' => '0'
);
} else {
$data = array(
'premium_count' => $premium_count-1
);
}
$this->admin_model->updateData('users', $data, $this->session->userdata('userid'));
模型函数(sql查询(:-
public function updateData($table,$data,$id)
{
$this->db->where('id',$id);
$this->db->update($table,$data);
}
当premium_count
的值为1,2,3..时,它可以工作,但当它减少到0时,它不会更新或将上面的列设置为0。
请尝试删除0s中的引号。我的意思是改变
if($premium_count == '0') {
$data = array(
'premium_count' => '0',
'premium_id' => '0',
'premium' => '0'
);
至
if($premium_count == 0) {
$data = array(
'premium_count' => 0,
'premium_id' => 0,
'premium' => 0
);
希望能有所帮助。
替换此部分,将零作为整数而不是字符串
$premium_count = !empty($logged_user[0]->premium_count) ? $logged_user[0]->premium_count : 0; // <- remove '' over zero
像这样检查
if($premium_count == 0) { // <- remove '' over zero
$data = array(
'premium_count' => '0',
'premium_id' => '0',
'premium' => '0'
);
} else {
$data = array(
'premium_count' => $premium_count-1
);
}