I posted this in here because i think its the JS thats wrong. Its probably something simple which i’m missing.
The MOST annoying thing is this works on my local environment, but when i upload it i have problems.
Basically i have a CSV file which i have built a php class to handle and on this page i get 3 random records from it and use the IDs to get the image names from a folder of images. I have an image class as well which takes an arr of IDs and gets the appropriate images. i.e if i send the ID’s TR34 and CO10 and ask for the thumbs it will return tBRANCH_TR34.jpg and tBRANCH_CO10.jpg.
This is used to make a property of the week display where it shows the image and brief description of the property. There is a next and previous button which the user can click to cycle through them. I’m not particularly good at JS and although this works perfectly on my local computer on a live server it displays the price and description, name and street, but it won’t get the image file names. Alerting the imageArr on the local version it displays the correct 3 filenames, doing the same on the live version it just shows two single quotes ”.
i’m 99% sure the php is all working, as i have copied the code onto the index page and and the filenames you will see under the logo are whats present in the $top_properties_arr.
The image that is present on load is just a dumby image hard coded and in another folder, the images i want are all in the images/ folder.
[url]http://www.eosinteractive.com/tandc/#
That is a test page ^
here is the code which is in a seperate file in a scripts folder on the server and is called in a javascript tag in the header.
nb: I guess the way i’m pushing the php array into the JS ones is a bit crap, but i’m not sure how to push a 2 dimensional associative php array into JS, so i seperated it into 5 JS arrays and then joined them into a 2 dimensional one.
[QUOTE]
<?php
//##################################
//### Includes
//##################################
include(‘../includes/class_lib.php’);
$images = new image_files(‘../images/’);
$csv = new csv_handler(“../xfile.csv”);
$random_properties_arr = $csv->get_random(3); //Get 3 random properties
foreach($random_properties_arr as $ID=>$header){ //create array of IDS
$ID_arr[] = $header[‘PropertyID’];
}
$image_arr = $images->get_by_ID($ID_arr,”thumb”); //Get images
$counter = 0;
foreach($image_arr as $ID=>$image){
$top_properties_arr[$counter][0] = $ID;
$top_properties_arr[$counter][1] = $image;
$top_properties_arr[$counter][2] = $random_properties_arr[$ID][‘ShortDescription’];
$top_properties_arr[$counter][3] = $random_properties_arr[$ID][‘PropertyName’];
$top_properties_arr[$counter][4] = $random_properties_arr[$ID][‘Street’];
$top_properties_arr[$counter][5] = $random_properties_arr[$ID][‘Price’];
$counter++;
}
?>
window.addEvent(“domready”, function(){
var imageArr = [];
var descriptionArr = [];
var IDArr = [];
var nameArr = [];
var streetArr = [];
var priceArr = [];
var topPropertiesDescription = [];
var pointer = 1;
<?php
$counter = 0;
foreach ($top_properties_arr as $single_property){ //push array to JS
print “IDArr.push(“$single_property[0]” );”;
print “imageArr.push(“$single_property[1]” );”;
print “descriptionArr.push(“$single_property[2]” );”;
print “nameArr.push(“$single_property[3]” );”;
print “streetArr.push(“$single_property[4]” );”;
print “priceArr.push(“$single_property[5]” );”;
}
?>
alert(imageArr);
var noProps;
noProps = imageArr.length;
topPropertiesDescription = new Array (noProps)
for (var i = 0; i < topPropertiesDescription.length; ++ i) topPropertiesDescription[i] = new Array (noProps); //int array
for(var i = 0; i < noProps; i++ ){ //concat arrays
topPropertiesDescription[i][0] = IDArr[i];
topPropertiesDescription[i][1] = imageArr[i];
topPropertiesDescription[i][2] = descriptionArr[i];
topPropertiesDescription[i][3] = nameArr[i];
topPropertiesDescription[i][4] = streetArr[i];
topPropertiesDescription[i][5] = priceArr[i];
}
$$(“.prev”).each(function(prevButton){ //previous property
prevButton.addEvent(“click”,function(){
if(pointer == 0){ pointer = imageArr.length; }
pointer–
$(“top_prop_image”).innerHTML = ‘<a href=”‘+topPropertiesDescription[pointer][0]+'”><img src=”images/’+ topPropertiesDescription[pointer][1] +'” width=”194″ height=”146″ /></a>’;
$(“title”).innerHTML = topPropertiesDescription[pointer][3];
$(“street”).innerHTML = topPropertiesDescription[pointer][4];
$(“short_description”).innerHTML = topPropertiesDescription[pointer][2].substr(1,65)+’…’;
$(“price”).innerHTML = topPropertiesDescription[pointer][5];
});
});
$$(“.next”).each(function(nextButton){ //next property
nextButton.addEvent(“click”,function(){
pointer++
if(pointer == imageArr.length){ pointer = 0; }
$(“top_prop_image”).innerHTML = ‘<a href=”‘+topPropertiesDescription[pointer][0]+'”><img src=”images/’+ topPropertiesDescription[pointer][1] +'” width=”194″ height=”146″ /></a>’;
$(“title”).innerHTML = topPropertiesDescription[pointer][3];
$(“street”).innerHTML = topPropertiesDescription[pointer][4];
$(“short_description”).innerHTML = topPropertiesDescription[pointer][2].substr(1,65)+’…’;
$(“price”).innerHTML = topPropertiesDescription[pointer][5];
});
});
});