如何处理未分配的记录
问题描述:
我有这个PHP页面,用户可以选择和取消选择项目。接口看起来是这样的:如何处理未分配的记录
现在我使用这些代码,当用户击中保存更改按钮:
foreach($value as $al_id){ //al_id is actually location id
//check if a record exists
//if location were assigned and leave it as is
$assigned_count = $this->AssignedLoc->checkIfAssigned($tab_user_id, $al_id);
if($assigned_count == 0){
//else if not, insert this new record
$this->insertAssigned($tab_user_id, $company_id, $al_id);
}
}
现在的问题是,如何删除未指定地点?例如在上面的屏幕截图中,如果我要从指定位置移除(或取消分配)“Mercury Morong”和“GP Hagonoy”,则只有两个必须保留。使用PHP的可能解决方案是什么?
感谢您的帮助!
答
循环访问不可用选择中的提交值。如果在“已分配”部分中存在具有该ID /名称/任何标识符的行,请从指定部分中删除该行。使用您预先存在的checkIfAssigned函数。