problem with script =/

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

Post Reply
philkills
Forum Newbie
Posts: 2
Joined: Sun Aug 28, 2005 4:57 am

problem with script =/

Post 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]
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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.
philkills
Forum Newbie
Posts: 2
Joined: Sun Aug 28, 2005 4:57 am

Post 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.... -__-
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

put print_r($images); after you finish setting that array and see what you get. remember the array starts with key 0
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you may need to sort the image list before you index into it as well.

mix strnatcasecmp() and usort()
Post Reply