Results 1 to 8 of 8

Thread: Php Photo Album Script not sorting by file name

  1. #1
    Join Date
    Jul 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Php Photo Album Script not sorting by file name

    Script url
    http://www.dynamicdrive.com/dynamici...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.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.

  3. #3
    Join Date
    Jul 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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)

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Try:

    Code:
    if (gsortorder=="asc" || gsortorder=="desc")
    galleryarray.sort(sortbydate)
    else 
    galleryarray.sort()
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jul 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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?

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by chuckster
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Jan 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Sorting by number is the same as sorting normally, just make the changes as mentioned (set gsortorder to an empty string):

    Code:
    var gsortorder=""
    And, add to the script as shown (additions red):

    Code:
    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
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •