PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
harkeyahh
Forum Newbie
Posts: 2 Joined: Wed Jun 16, 2004 8:31 pm
Post
by harkeyahh » Wed Jun 16, 2004 8:31 pm
For the purpose of letting everyone get what i'm trying to say i'm going to post my entire lines of script.
Code: Select all
$url = "http://www.harkeyahh.com/gallery/images/" ;
$dirname = "images/";
$dir = opendir($dirname);
while(false !=($file = readdir($dir) ) )
{if ( ("$file" != ".") AND ("$file" != "..") )
{
$harkeyfile[] = $file;
$file_list .="<li>$file</li>";
}
}
closedir($dir);
//Files in images are now in an array
sort($harkeyfile);
$mode = current($harkeyfile); // $mode = 0
list($width, $height, $type, $attr) = getimagesize("$url$mode");
echo"<img src="$url$mode" $attr />";
while( list( $element ) = each( $harkeyfile ) )
echo "<a href="$PHP_SELF?">$element<br /></a>";
$mode = next($harkeyfile); // $mode = 'bike';
list($width, $height, $type, $atrib) = getimagesize("$url$harkeyfile");
echo"<img src="$url$harkeyfile" $atrib />";
echo $mode . "\n";
echo "<a href="$PHP_SELF?$mode"> Next maybe?</a>";
$result = count($harkeyfile);
echo "Currently there are: $result images in the gallery";
?>
Now All I want to do is move forward and backward in the array. next() and prev() work i'm sure, but I don't know how to go about making a loop or using the functions in a link that would work for the task i'm trying to pull off. I'd like to keep the array on the same page since I plan on have a lot of images.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jun 16, 2004 8:51 pm
from what I remember:
while( list( $element ) = each( $harkeyfile ) )
echo "<a href=\"$PHP_SELF?\">$element<br /></a>";
after that, next() will return null/false.
harkeyahh
Forum Newbie
Posts: 2 Joined: Wed Jun 16, 2004 8:31 pm
Post
by harkeyahh » Wed Jun 16, 2004 9:13 pm
Soo your saying i need next();
before...
while( list( $element ) = each( $harkeyfile ) )
echo "<a href=\"$PHP_SELF?\">$element<br /></a>";
?
Hmm but what about the next prev link? how can that be accomplished?
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Wed Jun 16, 2004 9:27 pm
maybe a little class or something if you have not had any experience with them search this forum, there are many valid topics about classes
but here we go
Code: Select all
<?php
class array_handler {
var $array;
var $place = 0;
function define_array($array1) {
$this->array = $array1;
}
function forward($num = 1) {
$this->place = $this->place + $num;
return $this->array[$this->place];
}
function backward($num = 1) {
$this->place = $this->place - $num;
return $this->array[$this->place];
}
function print_array_location() {
print $this->array[$this->place];
}
}
$array_handler = new array_handler;
$array_handler->define_array(array(1,2,3,4,5,6,7,8,9,10));
$array_handler->forward();
$array_handler->print_array_location();
$array_handler->backward();
$array_handler->print_array_location();
?>