我有以下if statement
适用于 aninsert
但我似乎无法让它只使用未插入的项目更新表:
插入:
for($i=0; $i<count($fields['Occupation']); $i++) {
$id = $fields['Occupation'][$i];
CMS::insertQuery("INSERT INTO {table} SET canid=?, categoryid=?", array($emailCheck['id'], $id));
}
echo 'found update';
我尝试了以下更新行,但没有成功。
CMS::updateQuery("UPDATE {refocus_candidate_category} SET canid=?, categoryid=? WHERE canid=? AND categoryid=?", array($emailCheck['id'], $id));
完整声明:
$catParams = array_merge(array($emailCheck['id']), $fields['Occupation']);
$catPlaceholders = '?'.str_repeat(',?',count($fields['Occupation'])-1);
$catCheck = CMS::selectQuery("SELECT * FROM {table} WHERE canid=? AND categoryid IN (".$catPlaceholders.")", $catParams);
if($catCheck != FALSE)
{
for($i=0; $i<count($fields['Occupation']); $i++) {
$id = $fields['Occupation'][$i];
CMS::updateQuery("UPDATE {table} SET canid=?, categoryid=? WHERE canid=? AND categoryid=?", array($emailCheck['id'], $id));
}
echo 'found update'l
}else{
for($i=0; $i<count($fields['Occupation']); $i++) {
$id = $fields['Occupation'][$i];
CMS::insertQuery("INSERT INTO {table} SET canid=?, categoryid=?", array($emailCheck['id'], $id));
}
echo 'else insert';
}