Customizing SMF > SMF Coding Discussion
Multiple DELETEs with smcFunc ?
(1/1)
MrMorph:
Just having a look at smcFunc and deleting records. I understand this :
--- Code: ---$query = $smcFunc['db_query']('', "
DELETE FROM {db_prefix}mytable
WHERE id = {int:someint}",
array(
'someint' => 24,
)
);
--- End code ---
Works fine, but what if I want to do a lot of deletes at once ? In SQL I can do something like :
DELETE FROM table WHERE id = 1 OR id =12 OR id = 51;
But how can I use smcFunc to do this please, can you pass it an array ? Something like :
--- Code: ---$query = $smcFunc['db_query']('', "
DELETE FROM {db_prefix}mytable
WHERE id = {int:someint}",
array(
'someint' => array(1,12,51)
)
);
--- End code ---
Or something like that ?
Cheers :)
Marcus Forsberg:
WHERE id IN ({array_int:someint})
:)
MrMorph:
Aha ! Thank you good sir ;D
Marcus Forsberg:
That said, OR will also work as in your example
--- Code: ---$query = $smcFunc['db_query']('', '
DELETE FROM {db_prefix}mytable
WHERE id = {int:someint}
OR id = {int:someotherint}
OR id = {int:athirdint}',
array(
'someint' => 1,
'someotherint' => 23,
'athirdint' => 87,
)
);
--- End code ---
But of course, using an array is probably preferred, especially if you have a lot of different IDs to compare it to. :)
MrMorph:
Yeah looking at that and considering my ids could be anything I think the array approach is the one. Thanks again :)
Navigation
[0] Message Index
Go to full version