I wanna php output my mysql 1 as 01, 2 as 02.... and so on, so I get database ID first then I wrote this code for output
if ($id <10) {
echo '0'.$id;
} else {
echo $id;
}
and then I want to insert $id to my class then in a loop
while ($sth <100) {
$id = mysql_result($result,$mtt,"ID");
echo "<div class='active_$id'>$info</div>";
$sth++
}
how should i replace
if ($id <10) {
echo '0'.$id;
} else {
echo $id;
}
to $id
?
You should write:
$id = str_pad($id, 2, "0", STR_PAD_LEFT);