Hey there,
I hope anybody can help this little PHP newbie. And here's my problem 🙂
I've created a gallery for a website in which a user only has to add a directory which holds 16 images with specific filenames for it to show up in the gallery in full glory.
The code checks the main directory for any subdirectories and using those it creates links to view them. After that the code checks the to-be-viewed directory for the 16 images it holds and creates links using thumbnails with similar filenames stored elsewhere. All that works great until I tried to do a view-next-or-previous-image function. Basically you give two arguments, the current filename you're viewing, and whether it's a next or previous function
PrevNext($thefilename, "prev");
PrevNext($thefilename, "next");
Here's what my function looks like.
<?
function PrevNext($current, $which)
{
$preview = "000";
$prev = "000";
$next = "000";
$ep = "ep000";
for ( $g = 0 ; $g < 3 ; $g++ )
{
$preview[$g] = $current[$g+9];
$ep[$g+2] = $current[$g+2];
}
$prev = $preview;
$next = $preview;
if ( $which == "prev" )
{
switch ($prev)
{
case 001: printf("<<");
break;
default: $prev-=1;
printf("<A HREF=viewer.php?img=$ep");
printf("prev0");
if ($prev<=9)
{
printf("0");
}
printf("$prev.jpg><<</A>");
break;
}
}
if ( $which == "next" )
{
switch ($next)
{
case 016: printf(">>");
break;
default: $next+=1;
printf("<A HREF=viewer.php?img=$ep");
printf("prev0");
if ($next<=9)
{
printf("0");
}
printf("$next.jpg>>></A>");
break;
}
}
}
?>
When I use PrevNext($thefilename, "prev"); it works perfect. It adds an additional "0" if $prev is smaller or equal to 9 (somehow PHP deletes the extra 0 infront when I change it), and it doesn't print a link when the current file is the first in the gallery. Now PrevNext($thefilename, "next"); is a different story. It works thesame as "prev" when scrolling through images, but the link doesn't disappear at image 16, but at image 14. When I change it to "case 17" the link disappears at image 15, but when I change it to "case 18" the link will always be printed.
Am I missing something fundamental? I've done some C and C++, but this is my first shot at PHP. If you want to look at the code closer, here's what a filename looks like
ep009prev012.jpg
and a directory
ep009