SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Ireland
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Int field starting with 00

    Hi,

    I have a database and in the one table I have a field where I want to insert a numerical value starting with two zeros and then numbers after. I have tried INT and VARCHAR and both eliminate the 00 in the front and give me the rest of the number when I insert them. Why is this?

    Thanks for any help...

  2. #2
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    this will result in the 00 being shortened to 0:
    Code:
    insert datable (dacolumn)
    values (00);
    you need to insert into a varchar column like this:
    Code:
    insert datable (dacolumn)
    values ('00');
    but i have to ask, why do you need the leading zero? this is not the bast way to accomplish this.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    the best way to handle leading zeros in mysql is with the special ZEROFILL attribute

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Addict
    Join Date
    Sep 2005
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Not a number

    You're not really storing a number, you're storing a string. You need to use varchar and enter the data with quotes around it.

    0 = number or string
    00 = string, not a number
    01 = string, not a number
    PHP Shopping Cart Software Easy Ecommerce Shopping Cart Script.
    PHP Super Cart is 100% template driven.

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    no, no, no

    just use an UNSIGNED INTEGER datatype with ZEROFILL!!
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    SitePoint Addict
    Join Date
    Sep 2005
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're not doing math with the number then I recommend you store it as a string. You can add other characters if needed and perform string operations as well as get the proper indexing that you need when someone types in the "number".

    You should probably read the manual about zero fill to see if it will cause you problems in the future.

    http://dev.mysql.com/doc/refman/4.1/...ric-types.html
    PHP Shopping Cart Software Easy Ecommerce Shopping Cart Script.
    PHP Super Cart is 100% template driven.


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
  •