View Full Version : Source Order problem with PHP Album Script

05-16-2011, 08:49 PM
1) Script Title: PHP Photo Album script v2.11

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

3) Describe problem: I have successfully set up this on one of my websites with no problem, however now that I'm using a different host, I cannot get the right "Sort Order" for my uploaded pictures. One server goes:

Source Order: 1
Source Order: 2
Source Order: 3
and so on

the other
Source Order: 3
Source Order: 1
Source Order: 24
Source Order: Photo #
and so on

The photos seem to be in the right order but not the source which will not allow me to easily set a description for each. Does this have something to do with the Server or am I doing something wrong? The exact same files are on both servers, only the source order messes up in one of them.

05-17-2011, 03:02 AM
Generally the source order can be ignored. The 1st description will go with the first image, the second description with the second image, and so on. The source order may vary because the images were found in the order in which they were uploaded to the server. Once they are sorted by the script, everything should work out.

If this is not happening, it might be the host. But it might be some difference in the script you've missed, or a bug in the script.

If there really is a problem and you have the same images and code on both servers, give us a link to both of them so we can check it out.

05-17-2011, 02:04 PM
Host#1 (http://www.audiopipe.com/more/na_catalog2010/index.html)
Host#2 (http://www.audiopipe.com/more/na_catalog2010/index2.html)

Both html files are within the same server so I'm using the exact same scripts on both, I only changed both paths where the images are being hosted. getalbumpics.php within pictures folders is also the same. For now I will have to host the images/scripts on Host#1 and the code on Host#2. :rolleyes:

05-17-2011, 03:03 PM
It's a bug in the script. The script is sorting the array after the descriptions are assigned, so if the files weren't already in the final order (as in the case of Host#2) everything gets out of order. In ddphpalbum.js replace its function phpimagealbum with this one:

function phpimagealbum(setting){
this.albumvar.images.pop() //remove last "dummy" array element
this.dimensions=setting.dimensions || [3,3]
this.sortby=setting.sortby || ["file", "asc"],
this.onphotoclick=setting.onphotoclick || function(){}
this.photodivs=[] //array referencing each DIV that contains a slide
this.navlinks=null //HTML collection
if (setting.sortby[0]=="file") //sort by filename (asc)
this.albumvar.images.sort(function(a,b){return a[1].localeCompare(b[1])})
else //sort by date (asc)
this.albumvar.images.sort(function(a,b){return new Date(a[2])-new Date(b[2])})
if (setting.sortby[1]=="desc"){
for (var i=0; i<this.albumvar.images.length; i++){
if (this.albumvar.desc[i]) //if a manual desc exists for this image
this.albumvar.images[i][3]=this.albumvar.desc[i] //extend image array with desc

In case you're interested, the highlighted part is where the descriptions get assigned. It had been above the section where things get sorted, much closer to the beginning of the function. I moved it to just after the sorting, so its descriptions will go with the new sort order.

Speaking of the sort order, on index2.html, the sort order will not change (it's dictated by the sorting method and the order in which the files were uploaded to Host#2), but the descriptions will now each be with the proper image.

05-17-2011, 06:17 PM
Hey that was good! Host #1 is still fine while Host#2 now has the right description along with the images. The source order really doesn't matter to me as I remove it but it's the only thing that seemed to be wrong as I thought it went along with the description. Thanks! :)