increament number leading zeroes

Discussion in 'PHP' started by <?erick?>, Jul 20, 2008.

  1. #1
    hi everyone,

    anyone know how to increament number leading zeros and insert into mysql database..

    many thanks......
     
    <?erick?>, Jul 20, 2008 IP
  2. Cri2T

    Cri2T Peon

    Messages:
    104
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Mind explaining more?

    Incrementing numbers would be something like this:

    $number = 3;
    $number = $number + 1;

    And inserting the number into the database would be like so:

    mysql_query("INSERT INTO table (number) VALUES ('$number')") or die("Error");


    Now, I have a sneaky suspicion that you are trying to set the ID for each row of your table, this is achieved by setting up a column named 'id' (or anything else, but id = easy) and setting it as Auto_Increment and then setting it as the primary key.
     
    Cri2T, Jul 20, 2008 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,903
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #3
    You many need to set the column type of char and use a string padding function to do this.
     
    sarahk, Jul 22, 2008 IP
  4. 2slick

    2slick Peon

    Messages:
    73
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    a simple padding function would used something like this

    
    function padTenZeroes($number){// pad ten zeroes
        return sprintf("%010d",$number);
    }
    
    Code (markup):
     
    2slick, Jul 23, 2008 IP