1

我有以下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';
}
4

2 回答 2

1

我猜你需要类似下面的代码:

CMS::updateQuery("UPDATE {refocus_candidate_category} SET canid=?,
                  categoryid=? WHERE canid=? AND categoryid=?",
                  array($emailCheck['id'], $id, $emailCheck['id'], $id)
                );

?基本上,您需要与UPDATE语句中一样多的数组元素

于 2012-09-21T21:30:12.690 回答
0

好像你是两个数组项短:

CMS::updateQuery("UPDATE {refocus_candidate_category} SET canid=?, categoryid=? WHERE canid=? AND categoryid=?", array(
    emailCheck['id'], $id, ,'canid', 'cat_id number here');
);
于 2012-09-21T21:29:24.677 回答