auto_increment in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oranoos3000
    New Member
    • Jan 2009
    • 107

    auto_increment in php

    hi
    I want to have two field auto_increment
    in one table in database(mysql) that each other in when
    that table is created start with two digit for example one start with 110
    and the other start with 11111000,
    can I do this work?how?
    thanks alot
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    You want to look for auto_increment_ offset: http://dev.mysql.com/doc/refman/5.0/...crement_offset
    I have not used this and I am not sure how to enable it, but that will start you off. Please post back what you find so we can learn and help further.

    Comment

    • dlite922
      Recognized Expert Top Contributor
      • Dec 2007
      • 1586

      #3
      Originally posted by oranoos3000
      hi
      I want to have two field auto_increment
      in one table in database(mysql) that each other in when
      that table is created start with two digit for example one start with 110
      and the other start with 11111000,
      can I do this work?how?
      thanks alot
      I'm not sure this is the best way but this just came to mind.

      You can have an inline query that adds one to the previous record's second counter field.

      Code:
      INSERT INTO yourTable SET secondAutoInc = ((SELECT secondAutoInc FROM yourTable ORDER BY 1 DESC LIMIT 1) + 1);
      This is not a solution. There's a reason MySQL allows you to set only one auto-increment field: If you have a need for two, your application logic is screwed up.

      We might help you save time (and possibly money) if you explain your intentions and why you're trying to have two fields increment?



      *Boring to read, continue at own risk*:

      If you want to know why a record does not need to auto-increment consider this: When you ID (tag,lablel) something, anything can refer to it by this ID or tag. For example, we all need only ONE driver license number. The police and government can uniquley identify each person by their number so why have two numbers to be identified by. It will only make things more confusing.

      If your second field is not a key value (not used for identification but more of a display number (that is also unique)), then what you could do is just multiply (or add, subtract, divide) that field by a constant number to generate another unique ID. If you created a row with ID 5, your second field could be 5500 (5*1100). Here you just multiplied by 1100 to get another number that is better looking for an invoice or order number.

      ************ END OF BORING *************** ***


      Let me know if you have any questions,







      Dan

      Comment

      Working...