PDA

View Full Version : How do I place pictures in order



Tommisauce
11-05-2007, 01:29 PM
1) Script Title:
PHP Photo Album script

2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex4/php-photoalbum.htm

3) Describe problem:
Quite straightforward this issue - I just need to know how to place pictures in a sequential order. I have tried renaming photos pic01, pic02 etc. but this doesn't work, I've also tried to place pictures in the folder by created date, that didnt seem to work either. So my question is, is there anyway to label the pictures so that you can have them in a particular order on the gallery. I look forward to your comments.

Cheers
TS

boogyman
11-05-2007, 02:07 PM
//Sort images by date? ("asc", "desc", or "")
//"desc" for example causes the newest images to show up first in the gallery
//"" disables this feature, so images are sorted by file name (default)
var gsortorder="desc"

change gsortorder


var gsortorder="";

if you look at the descriptions above... disabling the order feature sorts the images by file name

jscheuer1
11-05-2007, 02:30 PM
That's not exactly so, Tommisauce and boogyman. It should be, but read on . . .

Strange, isn't it? The default sorting method is set in the script as (from the demo Step 2):


//Sort images by date? ("asc", "desc", or "")
//"desc" for example causes the newest images to show up first in the gallery
//"" disables this feature, so images are sorted by file name (default)
var gsortorder="desc"

in its configuration area. This means that the files will be sorted according to their date/time stamp in descending order, descending - I guess that means from biggest (most recent) to smallest (oldest), but to be frank I am only on my second cup of coffee, so it might be the other way around.

I don't need any coffee to tell you that the date/time stamp on the files are occasioned by their being uploaded to the server, and perhaps by being altered in some way once they are there, but uploading is the one part you can be certain of having control over.

So, you can upload the files one by one to (an empty directory on) the server, and that will be the order they will sort in, either froward or reverse of that. If you want to reverse it after uploading the files, just change this in the script:


var gsortorder="asc"

Unless you want to go through all that, which can have its merits in certain situations, but that is otherwise very cumbersome, you can sort alphabetically.

Unfortunately, where it says:


//"" disables this feature, so images are sorted by file name (default)

which should mean that doing this:


var gsortorder=""

will sort in alphabetical order, is just not true. That's just not how the subsequent code was actually written.

If you are interested in sorting that way, set that variable empty like it says to do, and also add to the script here (addition red):


/////No need to edit beyond here///////////////////

function sortbydate(a, b){ //Sort images function
if (gsortorder=="asc") //sort by file date: older to newer
return new Date(a[1])-new Date(b[1])
else if (gsortorder=="desc") //sort by file date: newer to older
return new Date(b[1])-new Date(a[1])
}

if (gsortorder=="asc" || gsortorder=="desc")
galleryarray.sort(sortbydate)

else
galleryarray.sort();

var totalslots=dimension.split("x")[0]*dimension.split("x")[1]

function buildimage(i){
var imagecompletepath=(targetlinkdir!="")? targetlinkdir+galleryarray[i][0] : imagepath+galleryarray[i][0]
var tempcontainer='<a href="'+imagec . . .

That will sort the files by filename A to Z to a to z, so make sure the names are all lower case. Numbers in the filenames will be treated as letters sorted alphabetically, not mathematically.

It can be made to sort the names mathematically if desired, but that means that letters in the filenames might mess everything up, and I think you have enough to go on now. And I want that third cup of coffee!

Tommisauce
11-05-2007, 03:42 PM
Lovely stuff - I followed your guides and this works a treat. Thanks very much for getting back to me so quickly.