Click to See Complete Forum and Search --> : problems with pic display


PunkSktBrdr01
08-07-2003, 12:35 PM
I made a picture viewer/slide show script with PHP and JavaScript, and I keep getting errors. I keeps saying "expected ';'", even though there is already a semicolon there. Here's the code:


<?

$pics = "mrc1.jpg,mrc2.jpg,mrc3.jpg,mrc4.jpg,mrc5.jpg,mrc6.jpg";

$src = explode(",", $pics);
$sizeof = sizeof($src);
$rows = ceil($sizeof / 4);
$cols = floor($sizeof / $rows);
$i = 0;
?>
<html>
<head>
<title>Pics</title>
<style>
img.thumb {
border:2;
border-color:#000000;
border-style:solid;
width:80px;
height:60px;
cursor:hand;
}
img.large {
border:0;
width:270px;
height:202px;
}
</style>
<script language="JavaScript">
function slideShow(dir) {
var pics = <?= $pics; ?>;
var pic_num = split(",", pics);
var i += dir;
if(i <= 0) {
document.slide_form.slide_left.disabled = true;
}
if(i >= pic_num.length) {
document.slide_form.slide_right.disabled = true;
}
}

</script>
</head>
<body>
<?
echo "<br>\n";
echo "<table width=\"100%\">\n";
echo "<tr><td><center>\n";
echo "<form name=\"slide_form\" onSubmit=\"return false;\">\n";
echo "<input type=\"button\" name=\"slide_left\" value=\"<<<\" onClick=\"slideShow(-1);\">\n";
echo "<img name=\"img\" width=\"270\" height=\"202\" src=\"$src[0]\">\n";
echo "<input type=\"button\" name=\"slide_right\" value=\">>>\" onClick=\"slideShow(1);\">\n";
echo "</form>\n";
echo "</center></td></tr>\n";
for($x = 0; $x < $rows; $x++) {
echo "<tr><td><center>\n";
for($y = 0; $y < $cols; $y++) {
echo "&nbsp;<img src=\"$src[$i]\" class=\"thumb\" width=\"80\" height=\"60\" onClick=\"document.img.src='$src[$i]'\">&nbsp;";
$i++;
}
echo "</td></tr>";
}
echo "</table>";
?>


The live code is here (http://www.radioactiverabbit.com/slideshow).
Thanks for any help!

Exuro
08-07-2003, 01:59 PM
There were a ton of bugs in that code, lol! I added several Else Ifs to the slideshow due to the fact that the buttons were a bit buggy... The buttons actually didn't do anything to the images in the code you posted :-p. But, you were probably going to add that in after you made the function work at all... Also, in the code you posted, when you clicked one of the thumbnails the value of i didn't change. Well, anyway, here's the code:


<?

$pics = "mrc1.jpg,mrc2.jpg,mrc3.jpg,mrc4.jpg,mrc5.jpg,mrc6.jpg";

$src = explode(",", $pics);
$sizeof = sizeof($src);
$rows = ceil($sizeof / 4);
$cols = floor($sizeof / $rows);
$i = 0;
?>
<html>
<head>
<title>Pics</title>
<style>
img.thumb {
border:2;
border-color:#000000;
border-style:solid;
width:80px;
height:60px;
cursor:hand;
}
img.large {
border:0;
width:270px;
height:202px;
}
</style>
<script type="text/javascript">
<!--
var i=1;
var pics = new Array(<?
for ($j=0;$j<$sizeof;$j++) {
echo "\"$src[$j]\"";
if ($j!=$sizeof-1) {
echo ",";
}
}
?>);
var pic_num = <?= $sizeof; ?>;

function slideShow(num) {
i=num;
if (i == 1) {
document.slide_form.slide_left.disabled = true;
}
else if (i >= pic_num) {
document.slide_form.slide_right.disabled = true;
}
else if (document.slide_form.slide_right.disabled) {
document.slide_form.slide_right.disabled = false;
}
else if (document.slide_form.slide_left.disabled) {
document.slide_form.slide_left.disabled = false;
}
document.img.src = pics[i-1];
}
//-->
</script>
</head>
<body>
<?
echo "<br>\n";
echo "<table width=\"100%\">\n";
echo "<tr><td><center>\n";
echo "<form name=\"slide_form\" onSubmit=\"return false;\">\n";
echo "<input type=\"button\" name=\"slide_left\" value=\"<<<\" onClick=\"slideShow(i-1);\" disabled=\"true\">\n";
echo "<img name=\"img\" width=\"270\" height=\"202\" src=\"$src[0]\">\n";
echo "<input type=\"button\" name=\"slide_right\" value=\">>>\" onClick=\"slideShow(i+1);\">\n";
echo "</form>\n";
echo "</center></td></tr>\n";
for($x = 0; $x < $rows; $x++) {
echo "<tr><td><center>\n";
for($y = 0; $y < $cols; $y++) {
echo "&nbsp;<img src=\"$src[$i]\" class=\"thumb\" width=\"80\" height=\"60\" onClick=\"slideShow(".($i+1).")\">&nbsp;";
$i++;
}
echo "</td></tr>";
}
echo "</table>";
?>

PunkSktBrdr01
08-07-2003, 02:59 PM
Thanks so much! It works great!