Reputation: 8385
I have the following if statement
that works fine for an insert
but I cannot seem to get it to only update the table with items that are not inserted:
Insert:
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';
I have tried the following update line with no luck.
CMS::updateQuery("UPDATE {refocus_candidate_category} SET canid=?, categoryid=? WHERE canid=? AND categoryid=?", array($emailCheck['id'], $id));
Full Statement:
$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';
}
Upvotes: 1
Views: 73
Reputation: 2339
My guess you need something like following code:
CMS::updateQuery("UPDATE {refocus_candidate_category} SET canid=?,
categoryid=? WHERE canid=? AND categoryid=?",
array($emailCheck['id'], $id, $emailCheck['id'], $id)
);
Basically you need as many array elements as ?
in your UPDATE
statement
Upvotes: 1
Reputation: 35256
Seems like you're two array items short:
CMS::updateQuery("UPDATE {refocus_candidate_category} SET canid=?, categoryid=? WHERE canid=? AND categoryid=?", array(
emailCheck['id'], $id, ,'canid', 'cat_id number here');
);
Upvotes: 0