Fill several mysql tables with the same info?

  • WritingBadCode
  • Graduate
  • Graduate
  • User avatar
  • Posts: 214
  • Loc: Sweden

Post 3+ Months Ago

Basically what I want to do is this, I have several tables created and I want it to be so when one is filled all the others gets filled as well with the SAME id. To be more precise a person signs up and he/she get a unique ID and what I want to happen are: table1 gets filled with the password and username the user chose when signing up and the user is assigned a ID with the help of mysql auto increase future. Then that ID gets pushed into table2 and table3 as well, (just the id)!

table1:
id
name
pass

table2:
id
more_info

table3:
id
picture
misc
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Here's what comes to my mind:

1) You submit the data into the first table (The one that holds the username, password... the one that creates that ID).
2) Retrieve the ID from that table
3) Insert that ID into the two other tables.


Another solution comes to mind:

1) Create all three tables with an ID that auto increment
2) When the user registers and the information is submitted into each table, the ID would auto increment by itself.

I think I like the second solution better... just make sure that every user gets the stuff in all tables at the same exact time that the first on is getting filled in
  • WritingBadCode
  • Graduate
  • Graduate
  • User avatar
  • Posts: 214
  • Loc: Sweden

Post 3+ Months Ago

Bogey wrote:
Here's what comes to my mind:

1) You submit the data into the first table (The one that holds the username, password... the one that creates that ID).
2) Retrieve the ID from that table
3) Insert that ID into the two other tables.


Another solution comes to mind:

1) Create all three tables with an ID that auto increment
2) When the user registers and the information is submitted into each table, the ID would auto increment by itself.

I think I like the second solution better... just make sure that every user gets the stuff in all tables at the same exact time that the first on is getting filled in


Thanks for your input, it got me thinking if I really must populate those fields instantly tho. :D Your first idea was what I had in mind but then I thought maby there is more brilliant solutions. So I posted this so I could hopefully learn a better way. If you got more ideas, feel free to share.

Solution #2 is a good one, is there a way to send data to all tables in just one query? I guess if there becomes any error and a user don't get a ID for some reason that populates one of the tables I could just add a "auto repair" function as long as the user has some sort of id!
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

I don't think that there is a way to insert into multiple tables with one query... You have to run more then one query for it.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 660
  • Loc: Conroe, Texas

Post 3+ Months Ago

I have a database that works kinda like bogey was talking about. it inputs the same into 2 different tables but its 2 querys and works wonders.
  • WritingBadCode
  • Graduate
  • Graduate
  • User avatar
  • Posts: 214
  • Loc: Sweden

Post 3+ Months Ago

Ok I guess I have to do it using several queries then.. Thanks

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 56 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.