Advanced Search

Results 1 to 7 of 7

Thread: Leading zeros

  1. #1
    Join Date
    Apr 2006
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Leading zeros

    I have the next code:

    Code:
    <select name="Ehour" id="Ehour" tabindex="3">
    									
    				  					<?php
    										for($n=0; $n <=24; $n++)
    										{ 
    									?>
                                        <option value="<? echo $n ?>"><? echo $n ?></option>
    									<?
    										}
    									?>
    									
                        		</select>
    I want this drop-dow show leading zeros for hours. Do you know how to do it??

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by pavmoxo
    I want this drop-dow show leading zeros for hours. Do you know how to do it??
    Use the str_pad function. For example:

    PHP Code:
    str_pad($n2'0'STR_PAD_LEFT
    Mike


    Please don't post such wildly-formatted code. Edit it so that, at the very least, it's not necessary for readers to scroll horizontally just to read it all.

  3. #3
    Join Date
    Apr 2006
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    In this code:

    Code:
    <option value="<? echo str_pad($n, 2, '0', STR_PAD_LEFT); ?>"><? echo str_pad($n, 2, '0', STR_PAD_LEFT); ?></option>
    appears 00 but doesn&#180;t insert the same to a mysql DB (only 0)

    Can you help me?

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

    Default

    It's probably being converted to an integer at some point during the server-side processing. We'd need to see that.
    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!

  5. #5
    Join Date
    Apr 2006
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The field is integer. Must be a string?

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

    Default

    Yes, any conversion to a number type will strip all leading zeroes (and trailing zeroes after the decimal point).
    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!

  7. #7
    Join Date
    Apr 2006
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank's a lot for everything. You are very cool!!!!!

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
  •