Jump to content

[SOLVED] for loop... adding 0 in front of nos. help please...


~n[EO]n~

Recommended Posts

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...

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>";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.