PDA

View Full Version : ok...php trouble



coolguy23
May 18th, 2001, 11:54
you guys helped me make this script

<center><html><body bgcolor="#000000" text="#FFFFFF" link="#FFFFFF"
vlink="#FFFFFF" alink="#FFFFFF">
<?$i=empty($i)?1:floor($i)?>
<img src="http://imagine.netfirms.com/img/<?=$i?>.jpg"> <br>
<p><font size="1" face="Arial,Verdana"><a href="<?=$PHP_SELF?>?i=<?=$i+1?>">Next Image</a>
|
<a href="<?=$PHP_SELF?>?i=<?=$i-1?>">Previous Image</a></font></p>
</center>
</html>


but there seems to be a problem, i have my images like 0001, 0002 and soo on but when i put .../display.php?i=0001 it shows picture 1.jpg instead of 0001.jpg
can someone fix this for me? woofcat? any1?
thanks

lucifer
May 18th, 2001, 12:30
you could rename your pics ;)

coolguy23
May 18th, 2001, 12:48
but i don't want to do that cuz then all the files aren't in order, i just want them to 0001 and that, can someone help

Woofcat
May 18th, 2001, 13:00
Change:

<?$i=empty($i)?1:floor($i)?>

to:

<?$i=sprintf('%04d',empty($i)?1:floor($i))?>

coolguy23
May 18th, 2001, 17:10
how about the next and previous buttons?
how do you fix those?
sorry if i bother you, i am not really good at php...

gyrbo
May 18th, 2001, 19:10
I don't know how to do it in PHP, but the theorie is that if you want image 0002 to load , and then count 1 with it PHP converts 0002 to 2 and then count 1 with it. You would just need to check how long the variable is and add as mutch zeros as needed.

Woofcat
May 18th, 2001, 21:47
Same thing... Change <?=$i+1?> and <?=$i-1?> to <?=sprintf('%04d',$i+1)?> and <?=sprintf('%04d',$i-1)?>