I have a playlist consisting of videos with positions.
In "delete selected video" section of my script, after deleting the selected video, I am updating the position of other videos on the playlist (stored on playlist_videos table), using the code below.
$playlist_videos = playlist_videos($playlist_id); // gets all videos on the given playlist, sorted by position
$i = 1;
foreach ($playlist_videos as $video) {
DB::$db->query("UPDATE playlist_videos SET position = $i WHERE video = ".$video['id']." AND playlist = $playlist_id");
$i++;
}
I currently do a foreach loop which results in multiple queries, and I am wondering if it is possible to turn it into one single query, to reduce DB load.
EDIT: A video can be on the same playlist multiple times, at different positions.