Jump to content

[SOLVED] Formating Numbers Help


syclonefx

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)

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.