Forum Moderators: coopster

Message Too Old, No Replies

Previous Next on image gallery

         

jackvull

1:25 pm on Oct 18, 2005 (gmt 0)

10+ Year Member



Hi
I have some PHP code, which iterates through some files in a folder and then displays links for the user to click:

// initialize counter
$count = 0;

// set directory name
$dir = "./eventpics";

echo "<table width = '400' cellspacing='0' padding='0' border='0'><tr><td>";

// open directory and parse file list
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
// iterate over file list
// print filenames
while (($filename = readdir($dh))!== false) {
if (($filename!= ".") && ($filename!= "..")) {
$pos = strstr($filename, 'Thumbs');
if ($pos == false) {
$count ++;

//Aspect ratio calculations
$max_width = 300; // maximum x aperture in pixels
$max_height = 220; // maximum y aperture in pixels
$size = GetImageSize($dir."/".$filename);
$width_ratio = ($size[0] / $max_width);
$height_ratio = ($size[1] / $max_height);

if($width_ratio >=$height_ratio) {
$ratio = $width_ratio;
}
else {
$ratio = $height_ratio;
}

$new_width = ($size[0] / $ratio);
$new_height = ($size[1] / $ratio);
if ($count == 21) {echo "</td></tr><tr><td>";} //new row for pictures
//Put in link
echo "&#160&#160&#160&#160<font size='2'><a class='gallery' href=".'"javascript:showimageinframe('."'".$dir."/".$filename."','myiframe',".$new_width.",".$new_height.");".'">'.$count."</a></font>&#160";
}
}
}
// close directory
closedir($dh);
}
}

Ideally, what I want is to do away with the links and replace them with Previous, Next buttons/arrows and have some JavaScript loading the images into an iframe.

How would I go about using JavaScript to do the previous, next events. Can I pass it an array from PHP and each time the next button is clicked just rewrite the innerHTML of the click buttons with a value from the array?

Thanks.

jatar_k

3:46 pm on Oct 18, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> Can I pass it an array from PHP and each time the next button is clicked just rewrite the innerHTML of the click buttons with a value from the array?

I believe you can do exactly that. Have php figure out what's next and write the js link.