|
|
|
|
| View previous topic :: View next topic |
| Author |
Message |
The Ragin' South Asian
Head Poncho
|
Posted: Fri Feb 04, 2005 1:43 am Post subject: 1 |
|
|
I'm writing this archive type thing for a friend since i have copious amounts of free time.
basically there's a folder with sequentially named files, and this is supposed to display the one with the highest number, which it does.
but the navigation doesn't work- i can't go back or foward in the sequence.
| Code: |
<td colspan=2>
<?php
$self = $_SERVER['PHP_SELF'];
$base="/Images/";
$num=CountFiles("./Images", "GIF");
if(!isSet($dispnum))
{$dispnum=sprintf("%03s",$num);
$dispnext=sprintf("%03s",$dispnum+1);
$dispprev=sprintf("%03s",$dispnum-1);
function CountFiles($dir, $type)
{
if(!($dh =@opendir("$dir")))
return false; // directory does not exist
// read the directory contents searching for "type" files
// and count how many are found:
$files = 0;
while ( ! ( ($fn = readdir($dh)) === false ) )
{
$f = strrev($fn);
$ext = substr($f, 0, strpos($f,"."));
$f_ext = strrev($ext);
if(( strcasecmp($f_ext, $type) == 0 )) $files++;
}
closedir($dh);
return $files;
}
?>
<img src="<?php print("$base$dispnum.GIF"); ?>">
</td>
</tr>
<tr>
<td>
<?php
if($dispnum>"001")
{
?>
<a href="<?php echo("$self?dispnum=$dispprev"); ?>">Previous</a>
<?php
}
else
{
print("Previous");
}
?>
</td>
<td>
<div align=right>
<?php
if($dispnum==$num)
{
print("Next");
}
else
{
?>
<a href="<?php echo("$self?dispnum=$dispnext"); ?>">Next</a>
<?php
}
?>
</div>
</td>
</tr>
</table>
</body>
</html> |
|
|
| Back to top |
|
 |
Bicho the Inhaler
Daedalian Member
|
Posted: Fri Feb 04, 2005 2:05 am Post subject: 2 |
|
|
I think you have an unterminated left brace: you probably want a right brace after
$dispnum=sprintf("%03s",$num);
It's kind of surprising that the parser didn't catch that (there are 6 right braces vs. 7 left braces), unless I missed something else. |
|
| Back to top |
|
 |
The Ragin' South Asian
Head Poncho
|
Posted: Fri Feb 04, 2005 2:19 am Post subject: 3 |
|
|
good catch, but i actually just screwed that up when pasting it in or something
my problem is with this stuff at the end
| Code: |
<tr>
<td>
<?php
if($dispnum>"001")
{
?>
<a href="<?php echo("$self?dispnum=$dispprev"); ?>">Previous</a>
<?php
}
else
{
print("Previous");
}
?>
</td>
<td>
<div align=right>
<?php
if($dispnum==$num)
{
print("Next");
}
else
{
?>
<a href="<?php echo("$self?dispnum=$dispnext"); ?>">Next</a>
<?php
}
?>
</div>
</td>
</tr> |
which i think should change the image, but for whatever reason doesn't
it doesn't generate an error or anything. it changes the url but not the picture. |
|
| Back to top |
|
 |
The Ragin' South Asian
Head Poncho
|
Posted: Sun Feb 06, 2005 8:20 am Post subject: 4 |
|
|
it had something to do with global variables or somesuch
adding $dispnum = $_GET['dispnum']; to the beginning fixed it |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|