/    Sign up×
Community /Pin to ProfileBookmark

Looking for some suggestions on ranking items in a db for page position

I have a CMS that I’m developing and on one table in my database I have a ‘position’ column. Right now when the user adds a new item I query the DB get the number of rows and add ‘1’ to get the next position. Easy enough.

When the user edits an item I get the number of rows and display them as options in a dropdown menu. This allows the user to reorder the how the items will appear on the page. However, there is nothing stopping the user from assigning any given position to multiple items. How can I prevent this? Is there something I could do when the edited item is resubmitted to the DB and if the selected position is occupied by a different item then add ‘1’ to all the positions following it?

I don’t know what the best way to do this is. Any suggestions or tips would be appreciated. By the way I’m pretty new at PHP. If you could explain any suggestion thoroughly I would definitely appreciate it ?

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @po3 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...