Jump to content

Recommended Posts

I am trying to get a double digit return. I am building a image gallery and I have a random number of image. The images are named feat_01.jpg thru feat_25.jpg. 

 

The out put of my code is: <div class="thumb"><a href="images/feat_1.jpg" class="feature">image1</a></div>

I want this out put: <div class="thumb"><a href="images/feat_01.jpg" class="feature">image01</a></div>

 

Is it possible to get a double digit return? I know I could change my echo statement to

echo '<div class="thumb"><a href="images/feat_0' . $i . '.jpg" class="feature">image0'. $i .'</a></div>';

This would work for 0 - 9, but if I do that once I get over 9 images this won't work.

 

<?php
$i = 01;
while ($i <= 25):
    echo '<div class="thumb"><a href="images/feat_' . $i . '.jpg" class="feature">image'. $i .'</a></div>';
    $i++;
endwhile;
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/107034-solved-formating-numbers-help/
Share on other sites

try... this isnt tested tho just a guess :P i want to try to help out

 
<?php
$i = 1;
$n = 0;
while ($i <= 25):
$n = $n + 1;    
echo '<div class="thumb"><a href="images/feat_' . $n . '.jpg" class="feature">image'. $n .'</a></div>';
    $i++;
endwhile;
?>

i don't know if this will work tho (i Don't use loops that much and iim kinda new)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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