The Grey Labyrinth is a collection of puzzles, riddles, mind games, paradoxes and other intellectually challenging diversions. Related topics: puzzle games, logic puzzles, lateral thinking puzzles, philosophy, mind benders, brain teasers, word problems, conundrums, 3d puzzles, spatial reasoning, intelligence tests, mathematical diversions, paradoxes, physics problems, reasoning, math, science.

   
The Grey Labyrinth Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups    RegisterRegister  
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

What is my mistake?

 
Reply to topic    The Grey Labyrinth Forum Index -> Science, Art, and Culture
View previous topic :: View next topic  
Author Message
The Ragin' South Asian
Head Poncho



PostPosted: Fri Feb 04, 2005 1:43 am    Post subject: 1 Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Bicho the Inhaler
Daedalian Member



PostPosted: Fri Feb 04, 2005 2:05 am    Post subject: 2 Reply with quote

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
View user's profile Send private message
The Ragin' South Asian
Head Poncho



PostPosted: Fri Feb 04, 2005 2:19 am    Post subject: 3 Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address
The Ragin' South Asian
Head Poncho



PostPosted: Sun Feb 06, 2005 8:20 am    Post subject: 4 Reply with quote

it had something to do with global variables or somesuch
adding $dispnum = $_GET['dispnum']; to the beginning fixed it
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Display posts from previous: by   
Reply to topic    The Grey Labyrinth Forum Index -> Science, Art, and Culture All times are GMT
Page 1 of 1

 
Jump to:  
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
Site Design by Wx3