Fill several mysql tables with the same info?

  • WritingBadCode
  • Graduate
  • Graduate
  • User avatar
  • Joined: Apr 28, 2011
  • Posts: 214
  • Loc: Sweden
  • Status: Offline

Post May 18th, 2011, 3:09 pm

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
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post May 18th, 2011, 3:09 pm

  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post May 18th, 2011, 3:25 pm

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
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • WritingBadCode
  • Graduate
  • Graduate
  • User avatar
  • Joined: Apr 28, 2011
  • Posts: 214
  • Loc: Sweden
  • Status: Offline

Post May 18th, 2011, 4:00 pm

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
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post May 18th, 2011, 4:09 pm

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.
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Joined: Jun 21, 2006
  • Posts: 485
  • Loc: Conroe, Texas
  • Status: Offline

Post May 18th, 2011, 5:39 pm

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.
Thanks, Josh --DemonMaestro
www.LilNetwork.com
Fun Website www.ShoutsCloud.com
  • WritingBadCode
  • Graduate
  • Graduate
  • User avatar
  • Joined: Apr 28, 2011
  • Posts: 214
  • Loc: Sweden
  • Status: Offline

Post May 19th, 2011, 10:12 am

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 83 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
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.