Picture slideshow from an array
Posted: Sat Dec 12, 2009 8:37 am
Hi everyone,
I've recently started to learn PHP and struggling to get some code working.
I've created an array with a few images in it, which I want to display on screen as a slideshow, with a next and previous button to go through each picture in the array. Although I can get an image to display on screen I can't get the next and previous buttons to take me to the next and previous images and display them on the same screen.
Here's my code:
<?php
$gallery[0] = 'ponies.jpg';
$gallery[1] = 'bird.jpg';
$gallery[2] = 'ant.jpg';
$gallery[3] = 'french.jpg';
$gallery[4] = 'cat.jpg';
$gallery[5] = 'leaves.jpg';
$countpic = 0;
$currentpic = $gallery[$countpic];
if ($countpic == count($gallery))
{
$currentpic = $gallery[0];
}
elseif($countpic == '-1')
{
$currentpic = count($gallery)-1;
}
echo "<div align=\"left\">";
echo "<table width=\"100%\">";
echo "<tr>";
echo "<td align=\"left\"><img src=\"";
echo $currentpic;
echo "\"/></td>";
echo "</tr>";
echo "</table>";
echo "<a href=\"$currentpic[$countpic]-1\">Previous</a>";
echo "|";
echo "<a href=\"$currentpic[$countpic]+1\">Next</a>";
?>
Does anyone know what I'm doing wrong here?
Thanks
I've recently started to learn PHP and struggling to get some code working.
I've created an array with a few images in it, which I want to display on screen as a slideshow, with a next and previous button to go through each picture in the array. Although I can get an image to display on screen I can't get the next and previous buttons to take me to the next and previous images and display them on the same screen.
Here's my code:
<?php
$gallery[0] = 'ponies.jpg';
$gallery[1] = 'bird.jpg';
$gallery[2] = 'ant.jpg';
$gallery[3] = 'french.jpg';
$gallery[4] = 'cat.jpg';
$gallery[5] = 'leaves.jpg';
$countpic = 0;
$currentpic = $gallery[$countpic];
if ($countpic == count($gallery))
{
$currentpic = $gallery[0];
}
elseif($countpic == '-1')
{
$currentpic = count($gallery)-1;
}
echo "<div align=\"left\">";
echo "<table width=\"100%\">";
echo "<tr>";
echo "<td align=\"left\"><img src=\"";
echo $currentpic;
echo "\"/></td>";
echo "</tr>";
echo "</table>";
echo "<a href=\"$currentpic[$countpic]-1\">Previous</a>";
echo "|";
echo "<a href=\"$currentpic[$countpic]+1\">Next</a>";
?>
Does anyone know what I'm doing wrong here?
Thanks