Fleur Posted March 15, 2010 Share Posted March 15, 2010 I'm building a CMS website where 5 images are displayed per page and the user can upload new images and select the position of the image / change the position after uploaded. I want to make it so that if you select a position (eg 2) that is already in use then the record that you are updating/adding will keep the position you have given it (ie 2), but the record that had that position before must be shifted down by 1 position (to 3) and the record that was 3 becomes 4 etc. I have no idea where to start with this. I'm using PHP 5.3.0 and MySql 5.1.36. Please let me know if you have any suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/195312-update-the-position-of-a-record-when-a-new-entry-is-given-that-position/ Share on other sites More sharing options...
ajlisowski Posted March 15, 2010 Share Posted March 15, 2010 UPDATE `images` SET `position`=`position`+1 WHERE `position`>=2 Quote Link to comment https://forums.phpfreaks.com/topic/195312-update-the-position-of-a-record-when-a-new-entry-is-given-that-position/#findComment-1026404 Share on other sites More sharing options...
Fleur Posted March 15, 2010 Author Share Posted March 15, 2010 Thanks ajlisowski! Now my problem is that if I move an image to a lower position then I need the other images to move positions up automatically so that you always have positions 1-5 and no blanks. Does anyone have a solution? Quote Link to comment https://forums.phpfreaks.com/topic/195312-update-the-position-of-a-record-when-a-new-entry-is-given-that-position/#findComment-1026501 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.