Jump to content

Archived

This topic is now archived and is closed to further replies.

graves_it

If statements

Recommended Posts

Using a simple php array to move thru files. The problem I am havin is if the last file, i dont now of a way to go back to the first.

Here is the code I am using.


[code]<?
$Files = array(); $Files[] = ""; $dirfiles =  opendir($dir); $imgcount = 1;

$imgcount = $imgcount-1;
if($pg == "" or $pg > $imgcount or $pg < 1){ $pg = $imgcount; }
$imagesource = $dir . $Files[$pg];
$imageinfo = getimagesize($imagesource);
$imageheight = $imageinfo[1];
$imagewidth = $imageinfo[0];

$lastpage = $pg +1;
if($lastpage < 1){ $lastpage = $imgcount; }

$nextpage = $pg -1;
if($nextpage < 1){ $nextpage = $imgcount; }
?>[/code]

Share this post


Link to post
Share on other sites
What your asking doesn't make any sense for the code that you've supplied.

Please either explain better, provide more code, or both.

Share this post


Link to post
Share on other sites
Here is all the code. This is a photo gallery that uses the date to order the pictures. Let say there are 3 picture. When you are on 3 and use $lastpage it goes to ?pg=4 instead of the begeinning ?pg=1.


[code]<?
$Files = array(); $Files[] = ""; $dirfiles =  opendir($dir); $imgcount = 1;
$cdate = date("Ymd"); $pg = $_GET['pg'];
if (! $dirfiles)
die('Can Not Find Any Images' . $dir);
while ($Filename = readdir($dirfiles))
{
    if($datedriven == true) {$fulldate = substr($Filename, 0, 8); }else{$fulldate = 0;}
    $fulldate = substr($Filename, 0, 8);
    if ($Filename == '.' || $Filename == '..' || $fulldate > $cdate)
    continue;
    $imgcount++;
    $Files[] = $Filename;
}
sort($Files);
$imgcount = $imgcount-1;
if($pg == "" or $pg > $imgcount or $pg < 1){ $pg = $imgcount; }
$imagesource = $dir . $Files[$pg];
$imageinfo = getimagesize($imagesource);
$imageheight = $imageinfo[1];
$imagewidth = $imageinfo[0];
if($datedriven == true)
{
    $month = substr($Files[$pg], 4, 2);
    $day = substr($Files[$pg], 6, 2);
    $year = substr($Files[$pg], 0, 4);
    $imagecolor = "#" . substr($Files[$pg], 12,6);
}else{
    $month = "";
    $day = "";
    $year = "";
    $imagecolor = $defaultbackcolor;
}

$lastpage = $pg +1;
if($lastpage < 1){ $lastpage = $imgcount; }

$nextpage = $pg -1;
if($nextpage < 1){ $nextpage = $imgcount; }
?>[/code]

Share this post


Link to post
Share on other sites
Change:

[code]$lastpage = $pg +1;
if($lastpage < 1){ $lastpage = $imgcount; }[/code]

to:

[code]$lastpage = $pg + 1;
if ($lastpage > $imgcount) {
    $lastpage = 1;
}[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.