views:

34

answers:

1

Hey there,

So, I've built-up a little gallery using a few plug-ins and some custom code. This is for a few photography website portfolios. So far, I've got the thumbnails in a UL on the left, and the larger image on the right. I've got some hover effects on the thumbnails, and onClick they fadeOut the larger image, swap SRC, load, then fadeIn again. It's neat. :)

I've also got an admin login that allows you to crop the thumbnail previews, upload new photos, and delete existing ones. The thumbnails are automatically generated using some PHP and readdir to echo the LIs.

So, that's the scenario, now here's my problem: I've got the .sortable() jQuery UI plug-in applied to my thumbnail UL, and I can drag them around, but I can't figure out for the life of me what would be a good way to go about capturing the new location of the thumbnails, and more importantly saving this! It's not a user preference, it's an admin control so cookies for each user wont work, I'd like it to actually edit how the site is displayed.

Should I have some PHP that takes the directory listing into an array and reorders it in some custom order? Should I have write some PHP to change the name of the image so PHP can automatically sort it on the next page load? MYSQL database for sort order? I really have no idea how this should be done! Ideas?

Thanks in advance for any advice! I know many others out there are wondering the same thing!

A: 

I'd use the jQuery.ajax() method to pass the file names and sort order to a PHP file that updates a table in MySQL. All you need in the table are two columns - one for filename and one for sort order.

Will Peavy
Oui oui, this is what I was thinking. I just didn't know if it made sense. As in, if there is already a known way of sorting these types of things used by image galleries. But, I suppose a MySQL table would be it! And, with the awesomeness of AJAX and blessings of jQuery, I could have one amazingly easy to use gallery. Woo!
BenjiBee
Benji, (from another Ben) the only gotcha here is thinking about if you move, say #5 to #3, how to reconcile the numbers. Your callback will tell you that the new position is #3, but now you're left with a hole in #5, the original #3 that has to be changed to #4, etc. So maybe best to update ALL value's orders with the toArray method.
bpeterson76
I'm wondering if it's possible to read the order of the LIs in the DOM and create an array with that. Numbering them as they appear in .sortable() sorted DOM. That would take care of both problems.. I wonder how..
BenjiBee