Originally I had one mysql video table that is shown to a user in a simple html table. They could select one or more checkboxes ($video_list
) to mark for deletion with a query (doesn't actually delete, but updates record)
//store all video names in array
foreach ($video_list as $element) {
$deleteNames[] = $db->quote($element);
}
//create nice comma separated list for query
$deleteNames = implode(',', $deleteNames);
// query used
$query_delete_video = sprintf('UPDATE `videos` SET deleted_datetime=NOW() WHERE `video_name` IN (%s)', $deleteNames);
Now the problem is that this html table now has images as well, not just videos. These images are in a separate table called images
. A user can select a number of videos or images at the same time or just videos or just images all for deletion.
So now the list $deleteNames
has potentially a mix of videos and image names.
The query for images alone would look like:
$query_delete_image = sprintf('UPDATE `images` SET deleted_datetime=NOW() WHERE `image_name` IN (%s)', $deleteNames);
Same thing just in a different table and different column name. The only way I can think of having these two queries is that I separate $deleteNames
into images and videos maybe by parsing the extension or something else.
Then I can run the query for each table. Is there a better way to tackle this, maybe in one query?