I am currently building a web application (a media player) using Javascript, PHP and MySQL. It will be used to upload videos and store them into a playlist, which can then be used by the user to place the videos in the desired order.
Uploaded files a saved in a MySQL database (id, title, file name and location, …). The question is, how can I save the order in which the user puts the playlist?
I don’t think adding a “position” field in the database is a good idea, as too many queries will be ran with each update. I thought of a “next” field, which points to the id of the next video in the list, which would “only” require a maximum of 3 queries for each update (right?).
Is there a better way to store the order of the playlist? It doesn’t particularly have to be in the database, it could be a text file as well I suppose.
Suggestions?
Thanks!
I think a ‘position’ field would be OK. You could update it with one statement after changing a track position, like this:
When inserting a new track just set :oldPos to a big value (bigger than any position on the list, so for example list length + 1) and :newPos to inserted track position, when removing a track set :oldPos to removed track position and :newPos to a big value.