auto_increment

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

auto_increment

Post by Parody »

i'm using the auto_increment option for mysql to generate an id for a group of people, this needs to be outputted to a main database and 4 other tables. how do i make sure it is the same id for all?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

mysql_insert_id
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: auto_increment

Post by Chris Corbyn »

Parody wrote:i'm using the auto_increment option for mysql to generate an id for a group of people, this needs to be outputted to a main database and 4 other tables. how do i make sure it is the same id for all?
Mind if I ask why it needs to be the same in the other 4 tables even when inserted? I think we could add a few columns to your tables to eliminate this need if I'm thinking the right thing about why you need this....
User avatar
zippee
Forum Newbie
Posts: 9
Joined: Wed Jun 22, 2005 6:28 am
Location: England

Post by zippee »

I normally create another field like 'my_id' after the auto_increment 'id' to have better control. I generate the 'my_id' based on date, ip &/or random number.

Note that you cannot search the database based on the auto_increment 'id' value, like $query = "SELECT * FROM table WHERE id = '$id' "; This will give you error.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

zippee wrote: Note that you cannot search the database based on the auto_increment 'id' value, like $query = "SELECT * FROM table WHERE id = '$id' "; This will give you error.
noooo if the auto_increment field is named 'id' then if i did that search it would not give you a error, i do it all the time
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

I read all of this and I managed to gather some info, thanks :)

BTW the id only needs to be unique in one of the tables, so am i right in saying I must insert the id here and use the function that was mention first?
Post Reply