Current location: Hot Scripts Forums » Programming Languages » PHP » Foreign Keys in MySQL and PHP


Foreign Keys in MySQL and PHP

Reply
  #1 (permalink)  
Old 02-04-08, 05:55 AM
davestar057 davestar057 is offline
Wannabe Coder
 
Join Date: Dec 2007
Posts: 115
Thanks: 1
Thanked 1 Time in 1 Post
Foreign Keys in MySQL and PHP

Hello Again,

Another quick question to clear up a little murky area in my head.



Because of nomalization we split tables up...and up and up etc..... Then we use FOREIGN KEYS to compare the info and link it etc.......

My question is......you set these foreign keys up in a table the same as you have set it up in the table where it is the Primary (cos every PK is nearly always the FK in another table)....The only thing is you cannot use the AUTO_INCREMENT because this is used for the PK in that field.

SO my question is..........how do you update the value of a FK ?????????? all the other fields would be filled in, and the AUTO_INCREMENT would take place on the PK .... but how would I update the FK?????????????????

I am getting confused with all this stuff.....I REALLY hope somebody can help clear some of this up for me as I am about to smash my head through my monitor! lol
Reply With Quote
  #2 (permalink)  
Old 02-04-08, 06:58 AM
Vicious's Avatar
Vicious Vicious is offline
Community VIP
 
Join Date: Jan 2007
Location: Belgium
Posts: 584
Thanks: 0
Thanked 0 Times in 0 Posts
you can get the PK from the one table via mysql_insert_id($link), and then use it to update the FK in the other table.
__________________
Jack Bauer makes Chuck Norris cry
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
PHP not recognizing admin in MySQL gizelle Database 3 04-15-07 08:39 PM
Php Mysql Bug??? tranquilraven PHP 4 03-01-06 03:06 AM
Need help with some php mysql TheTinkeringToad PHP 9 02-01-06 10:56 AM
MYSQL innoDB recognizing foreign keys cmmourik PHP 1 03-31-05 10:01 AM


All times are GMT -5. The time now is 07:34 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.