Dynamic sorting by user in page

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Adelyra
Forum Newbie
Posts: 3
Joined: Wed Sep 22, 2010 2:56 pm

Dynamic sorting by user in page

Post by Adelyra »

Hello!

I've got a site that has a dashboard where the user can log into and manage photos that they've uploaded. The user asked me, the other day, if there's a way to sort the images and what order they're displayed on the actual site. First, I'll explain the process the images go through from upload to displaying on the site:

-Upload file via upload form
-ID, Filename, Title, Category, and SortOrder are inserted to database (user defined except ID and Filename)
-Image is uploaded to directory (filename matches database)
-Call while(mysql_fetch_array) statement to display all images in specified category
-Sort by user specified SortOrder in ASC order

So, as you can see I've got a temporary solution for sorting where the user can assign a number to each image and then call a SELECT statement sorting in ASC order. The problem comes in when the user has 50 or so images per category and wants to add a picture to the top of the list. Then they would have to either have multiples with the same number or would have to re-number everything to allow that image to squeeze in.

Bottom line: Does anyone have any auggestions as to how I can create a dynamic sorting script where, when they want to add an image to the top, they don't have to go back in and re-number everything beneath thato one?

Let me know if you need an example of the code altough I don't know how much it would help It's more of a theory question.
Post Reply