Re: Add a leading zero
| From: | John | Date: | Wed, 24 Sep 2003 15:06:32 +0000 |
| Subject: | Re: Add a leading zero | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-163759@lists.php.net to get a copy of this message | ||
Take your result and use sprintf.
$variable_fixed=sprintf("%06s",$variable);
The above code with make $variable 6 digits long and fill all "empty" spaces
with zeros. So if $variable=42, the $variable_fixed with be 000042.
Specifically, for your code below, I would say put an if statement after the
while, but before the echo.
if ($i==0){
$i = sprintf("%02s",$i);
}
?>
<option value="<echo "$i"' ?>">"<? echo "$i"
?></option>
<?
John
"Shaun" <shaun@mania.plus.com> wrote in message
news:20030924124020.32022.qmail@pb1.pair.com...
> Hi,
>
> How can i add a leading zero to the first result of this loop so that i
get
> 00, 15, 30, 45?
>
> <select name="start_date_minute">
> <?php
> $i = 0;
> while ($i <= 45){
> echo '<option
> value="'.$i.'">'.$i.'</option>';
> $i+=15;
> }
> ?>
>
> Thanks for your help