Results 1 to 7 of 7

Thread: printing lead zero

  1. #1
    Join Date
    Aug 2006
    Posts
    65
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default printing lead zero

    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

    Code:
    print "<select name=\"Minute\">";
    			
    			for($min == 00; $min <= 60; $min++)
    			{
    			if($EventMinute == '$min')
    				{
    					print "<option value=\"$min\" selected=\"selected\">$min</option>";
    				}
    				else
    				{
    					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
    Code:
    <select name="Minute">
    			<option value="00">00</option>
    			<option value="01">01</option>
    			<option value="02">02</option>
    </select>
    
    ------------ 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?
    Last edited by Humper; 12-04-2006 at 06:37 PM. Reason: added some more code

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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:
    Code:
    function pad_num($num, $places) {
      $str = $num . '';
      while(strlen($str) < $places)
        $str = '0' . $str;
      return $str;
    }
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2006
    Posts
    65
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    Thank you .. that worked great....

  4. #4
    Join Date
    Aug 2006
    Posts
    65
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    How about inputting the leading zero..... is there a special way to do that?

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I don't understand you. Can you clarify?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Aug 2006
    Posts
    65
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    when i insert into the database it just inputs "4" if I clicked "04" the leading zero is always taken away..

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You need to store it in the database as a string.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •