473,409 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

auto_increment in php

oranoos3000
107 100+
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
Jan 25 '09 #1
2 1556
TheServant
1,168 Expert 1GB
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.
Jan 28 '09 #2
dlite922
1,584 Expert 1GB
@oranoos3000
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. INSERT INTO yourTable SET secondAutoInc = ((SELECT secondAutoInc FROM yourTable ORDER BY 1 DESC LIMIT 1) + 1); 
  3.  
  4.  
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
Jan 28 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Paul Lamonby | last post by:
Hi, i want to create a unique serial number to my Db entries. I thought the best way would be to add the auto_increment primary key value to a string, then insert it into a table field...
2
by: Ittay Freiman | last post by:
i cannot set auto_increment to start from anything other than 1: mysql> create table test (id int unsigned not null auto_increment primary key); mysql> alter table test auto_increment=2; ...
9
by: Bart Van der Donck | last post by:
Hello, The first column of my table is AUTO_INCREMENT. I fill my table with 5 records with a blanco value in their first field. The first column of my table will then hold the values 1,2,3,4,5...
0
by: Shailesh | last post by:
I made a MyISAM table on mysql 4.0.18 NT with auto_increment column started at 2147483646. The third row I insert fails as expected because the integer range is maxed out. However, if I delete...
0
by: Shailesh | last post by:
I made a MyISAM table on mysql 4.0.18 NT with auto_increment column started at 2147483646. The third row I insert fails as expected because the integer range is maxed out. However, if I delete...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.