Vitamin Posted April 2, 2009 Share Posted April 2, 2009 Hey, I'm familiar with relations in Access, but they are so much more difficult for me to understand in MySQL. Here is my problem. I have 2 tables one named task with PK of taskid which is auto_increment and another table that is ipaddress with a PK of taskid which is auto_increment. I have a php page which inserts data into the task table and then inserts the ipaddress into the ipaddress table. The problem is I have like 100 entries in the task table and I just created the ipaddress table. How can I create a relation between the two tables? Quote Link to comment Share on other sites More sharing options...
fenway Posted April 2, 2009 Share Posted April 2, 2009 Wait a minute... you can't have taskid being auto-increment in *TWO* places?!?! Quote Link to comment Share on other sites More sharing options...
Vitamin Posted April 2, 2009 Author Share Posted April 2, 2009 Hey I found that out sorry Ok so I guess what I want to do is when the task table gets a id I want to to put that same number in the ipaddress table. How can I go about doing that? Quote Link to comment Share on other sites More sharing options...
thepip3r Posted April 2, 2009 Share Posted April 2, 2009 after your INSERT to the task table, use mysql_insert_id() to get the id of the last insert and then use the value returned there to insert a that id into your ipaddresses table. http://us3.php.net/manual/en/function.mysql-insert-id.php Quote Link to comment Share on other sites More sharing options...
Vitamin Posted April 2, 2009 Author Share Posted April 2, 2009 Yes thats going to work thanks a ton! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.