PDA

View Full Version : Php Photo Album Script not sorting by file name



chuckster
05-04-2006, 03:16 AM
Script url
http://www.dynamicdrive.com/dynamicindex4/php-photoalbum.htm

var gsortorder=""

When I look at the server with ftp, the files are correctly sorted alphabetically.

My url
http://www.chuckroast.com/emb/inst/emb-inst.php

I'm stumped (a fairly frequent occurrence)

Any help would be appreciated.

djr33
05-04-2006, 04:16 AM
When I look at the server with ftp, the files are correctly sorted alphabetically.Yeah. That's what ftp does. Not php. You could order alphabetically, but i'm not sure how exactly.

Look for an alphabatize function on php.net. Or write one yourself... but that would be a pain.

What exactly do you want? Just alphabetic sorting of your images on the page? Not quite clear on that.

chuckster
05-04-2006, 04:25 AM
Yes. I need them sorted by file name and the script would indicate that as the default. They are not sorted by date or file name in the script. I don't know what to change.

//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=""

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)

jscheuer1
05-04-2006, 05:28 AM
Try:


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

chuckster
05-04-2006, 05:36 AM
Thanks. I had just discovered that myself at the very same time you posted. (or were you sending that by ESP?)

Do you change the script that is listed when a change is needed?

jscheuer1
05-04-2006, 05:53 AM
Thanks. I had just discovered that myself at the very same time you posted. (or were you sending that by ESP?)

Do you change the script that is listed when a change is needed?

ESP, perhaps but, I only post here. :rolleyes:

markusv3000
01-24-2007, 01:23 AM
hi,
i'm still having a problem with trying to make to sort. i'm trying to sort from the last number to first. how do i do this?

i seen you guys post "sortbydate", does this mean i need to name the images a certion way. please help

jscheuer1
01-24-2007, 04:49 AM
Sorting by number is the same as sorting normally, just make the changes as mentioned (set gsortorder to an empty string):


var gsortorder=""

And, add to the script as shown (additions red):


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

However, sorting by number works just like a directory listing so, if there are two digits in some of your filenames, the ones with single digits must be padded with zeroes. Use:

01
02
03
04
etc., until 10, then:
10
11
12 . . .

If you have three digits:

001
002
003
etc., until 10, then:
010
011
etc., until 100, then:
100
101
102 . . .

not:

1
2
3
4
5
6
7
8
9
10
11
12 . . .

And, unless the filenames are otherwise identical, the number portion must come at the beginning of the filename:

photo_01.jpg
photo_02.jpg

is OK but not:

dog_01.jpg
cat_02.jpg

but, this will work:

01_dog.jpg
02_cat.jpg