需要帮助,在我的函数底部,我试图从数组中删除一个值,所以当我从数组中取消设置一个值并使用同一变量执行 print_r() 时,它显示它已被删除,但是!当我使用相同的变量将其插入数据库时,它显示原始值,我不知道为什么......有什么想法吗?
public function updateProjectCommunity() {
$data = fetch_query();
$this->db->start_cache();
$this->db->trans_start();
$this->db->select('memberships');
$this->db->from('org_projects_team');
$this->db->where('project_id', $data->projectId);
$response = $this->db->get()->result_array();
$count = $this->db->count_all_results();
if ($data->action == 'assign') {
if ($count == 0) {
$members = array();
$members[$data->title][] = $data->person;
$members_sorted = array_unique($members);
$members_update = array(
'project_id' => $data->projectId,
'memberships' => JSON_encode($members_sorted)
);
$this->db->insert('org_projects_team', $members_update);
var_dump($members_sorted);
} else {
$members = array();
$members[$data->title][] = $data->person;
$members_sorted = array_unique($members);
$members_update = array(
'memberships' => JSON_encode($members_sorted)
);
$this->db->where('project_id', $data->projectId);
$this->db->set('memberships', JSON_encode($members_sorted));
$this->db->update('org_projects_team');
var_dump($members_sorted);
}
} else {
if ($count > 0) {
$assigned_category = JSON_decode($response[0]['memberships'], true);
foreach($assigned_category[$data->title] as $key => $value) {
if ($value = $data->person) {
if(is_array($assigned_category[$data->title])) {
unset($assigned_category[$data->title][$key]);
$update = $assigned_category;
$this->db->where('project_id', $data->projectId);
$this->db->set('memberships', JSON_encode($update));
$this->db->update('org_projects_team');
}
}
}
print_r($assigned_category);
$error = array(
'status' => true,
'text' => "Successful"
);
} else {
$error = array(
'status' => false,
'text' => 'Error Occured'
);
}
return $error;
}
$this->db->trans_complete();
$this->db->flush_cache();
}
我发现我的代码工作正常,MYSQL Workbench 只是对我来说有点问题,我对 Workbench 不满意,我需要更好的东西