Auto Increment

Discussion in 'PHP' started by oo7ml, Sep 16, 2007.

  1. #1
    I have a ID field that auto increments ID's when a user joins. I have 138 users at the moment. However i want to give users a 6 digit ID, so i was thinking of setting ID's for any new users who join at 100001, instead of moving onto 139

    How would i go about doing this...
     
    oo7ml, Sep 16, 2007 IP
  2. Philopoemen

    Philopoemen Peon

    Messages:
    704
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You specify that when You create the database table. You can set the starting point of the INT unique field. That is if you want the ID to be specified automatically by MySQL, when a row is inserted.
    But ofc you can do it manually, just check which is the biggest existing ID in the table, and next user gets $id = $existingID++; :)
     
    Philopoemen, Sep 16, 2007 IP
  3. amorph

    amorph Peon

    Messages:
    200
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yep...you could set the start of increment from mysql or drop the auto_increment feature from mysql and leave this job in PHP's hands. The second will take more resources with it since the script will have to do a query to extract before figuring out what's the biggest ID in the db and than increment it via ++.
     
    amorph, Sep 16, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    
    ALTER TABLE your_table AUTO_INCREMENT = 100000
    
    Code (sql):
     
    nico_swd, Sep 16, 2007 IP