Need help in Auto Increment to add a default number

Discussion in 'PHP' started by jehzlau, Jul 15, 2007.

  1. #1
    Need help in Auto Increment to add a default number. How can i add a number before the number to be auto incremented in php using mysql database... for example i want my ID to be 0001

    after adding a row in the table, the ID would be 0002, and so on and so forth...

    but I can't it only shows... 1, 2, 3, then 4 and so on.. is it possible to make my integers start with 3 zeroes or 2 zeroes, and if it will arrive to 10, only two zeroes will appear before the number instead of three?

    for example, 0001, 0002... 0010, 0011, 0012...

    how can i do it in mysqL? :(

    need help anyone, i hope u got my point T___T

    i'm a very newbie in this stuff T_T
     
    jehzlau, Jul 15, 2007 IP
  2. sm9ai

    sm9ai Active Member

    Messages:
    746
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Set the length of the field to 4, then use the attribute UNSIGNED ZEROFILL
     
    sm9ai, Jul 16, 2007 IP
  3. jehzlau

    jehzlau Active Member

    Messages:
    301
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    73
    #3
    wow thanks for this! weeeeeee! i'm so noob T___T thank you so much :)
     
    jehzlau, Jul 22, 2007 IP
  4. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #4
    is there a reason for this? i mean starting at 1 really hurts nothing. for display purposes simply
    echo sprintf("%04d",$row['id']);
    PHP:
     
    ansi, Jul 23, 2007 IP