Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image gallery problem!!!!

Status
Not open for further replies.

DGK101

Programmer
Jan 9, 2003
33
ZA
Hi

I wonder if anyone can help me?
I copied a picture gallery script off of the following website:


The problem i am having is that the gallery starts off fine, i can view the pics and it gives me nav links to navigate the pictures, BUT as soon as i click on the next link OR i click on a picture to view the larger version - it gives me an error message.

you can view my picture gallery at :
to get an idea of what messages i recieve.

i will also include all the code i have included in the file at the bottom of this message.
I am new at PHP so i am probably not picking a mistake up somewhere????
Please help!! i have been racking my brain.
thanks.

<html>
<head>
<title>photo gallery</title>
<script language=&quot;javascript&quot;>
<!--
function photo_open(link, width, height)
{
var photoWindow = window.open(link,&quot;photo&quot;,
'toolbar=0,location=0,directories=0,status=0,
menubar=0,scrollbars=0,resizable=0,width=
'+width+',height='+height);
}
//-->
</script>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;
link=&quot;#00CCFF&quot; alink=&quot;#00CCFF&quot; vlink=&quot;#00CCFF&quot;>

<table cellpadding=&quot;2&quot; align=&quot;center&quot;
cellspacing=&quot;2&quot; width=&quot;80%&quot; border=&quot;0&quot; >

<?PHP
//initialize variables
$data_file = &quot;list.photos.txt&quot;;
$thumbnail_dir = &quot;thumbs/&quot;;
$num_rows = 3;
$photos_per_row = 3;
$photos = file($data_file);
$total_photos = sizeof($photos);
$photos_per_page = $num_rows * $photos_per_row;
//check to see if the start variable exists in the URL.
//If not, then the user is on the first page - set start to 0
if(!isSet($start)){
$start = 0;
}
//init i to where it needs to start in the photos array
$i = $start;
$prev_start = $start - $photos_per_page;
$next_start = $start + $photos_per_page;
for ($row=0; $row < $num_rows; $row++){
print(&quot;<tr>\n&quot;);

for ($col=0; $col < $photos_per_row; $col++){
if($i < $total_photos){
$thumbnail = $thumbnail_dir.trim($photos[$i]);
$thumb_image_size = getimagesize($thumbnail);
$image_size = getimagesize(trim($photos[$i]));
print(&quot;<td align=\&quot;center\&quot;>
<a href=\&quot;javascript:photo_open('photo_display.php?photo=
&quot;.trim($photos[$i]).&quot;','&quot;.$image_size[0].&quot;','
&quot;.$image_size[1].&quot;');\&quot;>
<img src=\&quot;&quot;.$thumbnail.
&quot;\&quot; &quot;.$thumb_image_size[3].&quot;></a></td>\n&quot;);
} else {
print(&quot;<td></td>\n&quot;);
}
$i++;
}
print(&quot;</tr>\n&quot;);
}

//end table
?>
</table>

<div align=&quot;center&quot;>
<?PHP
//print out navigation links
if(($start == 0) && ($next_start < $total_photos)){

//you're at the beginning of the photo gallery

?>
<font face=&quot;arial, helvetica&quot; size=&quot;2&quot;>
<b><a href=&quot;index.php?start=<
?PHP print($next_start):?>&quot;>next page</a>
<font color=&quot;#FF0000&quot;>»</font></b>
</font>
<?PHP
}
elseif (($start > 0) && ($next_start < $total_photos)){

//you're in the middle of the photo gallery

?>
<font face=&quot;arial, helvetica&quot; size=&quot;2&quot;>
<b><font color=&quot;#FF0000&quot;>«
</font> <a href=\&quot;index.php?start=
<?PHP print($prev_start); ?>&quot;>prev page</a></b></font>
<b>|</b>
<font face=&quot;arial, helvetica&quot; size=&quot;2&quot;>
<b><a href=&quot;index.php?start=<
?PHP print($next_start); ?>&quot;>next page</a> <font
color=&quot;#FF0000&quot;>»</font></b></font>
<?PHP
}
elseif(($start == 0) && ($next_start > $total_photos)){

//you're in a photo gallery with only one page of photos

?>

<?PHP
}
else {

//you're at the end of the photo galley

?>
<font face=&quot;arial, helvetica&quot; size=&quot;2&quot;>
<b><font color=&quot;#FF0000&quot;>«</font>
<a href=&quot;index.php?start=<?PHP print($prev_start); ?>
&quot;>prev page</a></b></font>
<?PHP
}
?>

</div>
</body>
</html>
 
According to Mozilla's javascript console you have an unterminated string constant in your javascript.

Something about the way you output that function... I would try putting it all on one line if I were you... but there's definately a javascript problem with your page.

-Rob
 
HTML and JavaScript consider whitespace differently.
Your output of the URL that is passed to the JavaScript functions contains linebreaks and extra spaces.
To pass GET parameters, i.e. a querystring, the parameter should start right after the assignment operator:
Code:
BAD:
<a href=&quot;javascript:photo_open('photo_display.php?photo=
        P0007987.jpg','384','
        256');&quot;> 
GOOD:
<a href=&quot;javascript:photo_open('photo_display.php?photo=P0007987.jpg','384','256');&quot;>
The arguments passed to the JavaScript function need to be exactly formatted.
Once you fix that all will work fine.
 
Thanks guys, the info was very helpful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top