~n[EO]n~ Posted November 30, 2007 Share Posted November 30, 2007 Hi, I have this code which will loop the given directory and shows all the images in one page, problem I am facing is till image 9, file names are given as 01...09. How to work with that <?php $i = 01; for ($i=01; $i<=110; $i++) { echo "<div><img src=\"http://localhost/drawings/3d_drawing_models/images/".$i.".jpg\" /></div>"; } ?> Any help.. Thanks... Link to comment https://forums.phpfreaks.com/topic/79523-solved-for-loop-adding-0-in-front-of-nos-help-please/ Share on other sites More sharing options...
Wes1890 Posted November 30, 2007 Share Posted November 30, 2007 You can't have 01 as a variable.. do this instead <?php for ($i=1; $i<=110; $i++) { if ($i < 10) { $i = "0".$i; } else { } echo "<div><img src=\"http://localhost/drawings/3d_drawing_models/images/".$i.".jpg\" /></div>"; } ?> Link to comment https://forums.phpfreaks.com/topic/79523-solved-for-loop-adding-0-in-front-of-nos-help-please/#findComment-402753 Share on other sites More sharing options...
~n[EO]n~ Posted November 30, 2007 Author Share Posted November 30, 2007 EDIT: Sorry LOL... forgot to change the path... works perfectly now Thanks Link to comment https://forums.phpfreaks.com/topic/79523-solved-for-loop-adding-0-in-front-of-nos-help-please/#findComment-402756 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.