I have a client I am building a small CMS for. One of the functions is that he would like to be able to pick the order in which images display on a page.
In my mySql Database I have a table called image_info with the fields:
index (auto incremented)
img_url
img_link
I was thinking of adding an additional field called img_order which would be an int that I would refer to to sort the data returned to my php script.
I’m not sure if that is the best way. I feel like I will have to be re numbering every entry in the database just to move one image up or down the list.
Is there a standard procedure for this type of function?
Thanks,
-J
I think that adding an
img_ordercolumn is the easiest way, and it won’t be hard be to renumber the fields. For instance, if you’re adding a picture atimg_orderposition 15, just insert it with that value, then run the following query:If you’re removing an existing image, you’d have to decrease the
img_ordervalues for all images after that one:And if you’re moving an image from one position to another, you’d have to increment the
img_orderfor all images between the original and new position: