Page 1 of 1

problem with script =/

Posted: Sun Aug 28, 2005 5:53 am
by philkills
Hi can anyone tell me whats wrong with this script:

Code: Select all

<?php
if (isset($_POST['item'])) {
if ($_POST['itemnum'] > "") {
$itemnum = $_POST['itemnum'];
$image_dir = 'images/Soma/Items';
$itemnum = $itemnum;
if(!is_dir($image_dir))
{
echo ('Sorry but that is not a Direcotry.');
exit;
}

if(($dir_open = opendir($image_dir)) == false)
{
echo ('Error-- Could not open Directory');
exit;
}

while(($read_dir = readdir($dir_open)) != false)
{
if(!preg_match('/^\.+$/',$read_dir))
{
if(preg_match('/gif|jpeg|jpg|ico|png$/', $read_dir))
{
$images[] = $read_dir;
}
}
}
echo "<img src=\"images/soma/items/$images[$itemnum]\">";
}
}
?>
Basically i would like an image to change based on the value of an input box... i would also like the value of the input box to remain the same as the person input into it...rather than resetting itself. Also if there was a way for this code to be loaded based on a change in value of the input box that would be good too ^_^

Any help on this matter is greatly appreciated.... spent ages searching to no avail

Thanks ^^


feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sun Aug 28, 2005 6:48 am
by shiznatix
first of all, use

Code: Select all

tags

second of all, what is not working about it? your $_POST['itemnum'] > '' probebly is not going to work, you might wanna try using != instead of > for that.

for the last part they u said you might wanna use javascript.

Posted: Sun Aug 28, 2005 6:52 am
by philkills
well first of all if i type in the value 1 it will load image 10....

It also doesnt want to load any image higher than 30.... -__-

Posted: Sun Aug 28, 2005 7:00 am
by shiznatix
put print_r($images); after you finish setting that array and see what you get. remember the array starts with key 0

Posted: Sun Aug 28, 2005 8:34 am
by feyd
you may need to sort the image list before you index into it as well.

mix strnatcasecmp() and usort()