View Full Version : printing lead zero

12-04-2006, 06:32 PM
I need this to print out with the leading zero just for numbers 1-9 the rest is fine.... right now it doesn't even print out the 0 it just starts with 1

print "<select name=\"Minute\">";

for($min == 00; $min <= 60; $min++)
if($EventMinute == '$min')
print "<option value=\"$min\" selected=\"selected\">$min</option>";
print "<option value=\"$min\">$min</option>";

I have tried to make $min == "00"; and also tried $min == '00'; neither work...

another issue I am having which is probably related to this same issue is that when I input a var into the database it doesn't add the first zero.

I know this first part is not php but it relates to my question.. second part is php

<select name="Minute">
<option value="00">00</option>
<option value="01">01</option>
<option value="02">02</option>

------------ inserting here from php file ------------

$insert = "INSERT INTO SiteEvents(EventMinute) VALUES('".addslashes($EventMinute)."')";

Is there something special I have to do to make it insert and print the leading zero?

12-04-2006, 07:24 PM
Integers always drop leading zeroes. If you want to keep it, you must use a string, or convert the integer to a string before outputting:
function pad_num($num, $places) {
$str = $num . '';
while(strlen($str) < $places)
$str = '0' . $str;
return $str;

12-04-2006, 08:10 PM
Thank you .. that worked great....

12-04-2006, 08:13 PM
How about inputting the leading zero..... is there a special way to do that?

12-04-2006, 08:23 PM
I don't understand you. Can you clarify?

12-05-2006, 01:49 PM
when i insert into the database it just inputs "4" if I clicked "04" the leading zero is always taken away..

12-05-2006, 06:16 PM
You need to store it in the database as a string.