Something like this, perhaps? <? // your INSERT to first table here. $insert_id = mysql_insert_id();
$sql = "SELECT MAX(SecondID) FROM LookupTable WHERE FirstID = $insert_id"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $max_second_id = $row[0]; $sql = "INSERT INTO LookupTable VALUES ($insert_id, $max_second_id + 1)"; $result = mysql_query($sql); ?> Might be some errors in it, but you get the idea. Regards Joakim Andersson > -----Original Message----- > From: Graeme McLaren [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, September 03, 2002 5:42 PM > To: [EMAIL PROTECTED] > Subject: [PHP-DB] INSERTing INTO Multiple Tables with MySQL & PHP > > > Hi there, I've been hunting thru the net trying to find some info on > inserting data to multiple tables. > > I have two tables (LookupTable and MainTable): > > LookupTable( > FirstID > SecondID > ) > > MainTable( > ID > Name > Address > etc > etc > ) > > Once I insert data into the MainTable I want to also insert > the ID from the > MainTable to the LookupTable as the FirstID. Then I want to > check for the > highest ID number in the SecondID field that is associated > with the First ID > then add one to the highest value and insert that to the SecondID. > FirstID SecondID > 1 1 > 1 2 > 1 3 > 1 4 > > In the above table I would want to insert 1 to the FirstID > then find the > highest number in the SecondID associated with the FirstID > "1" then add one > to it so that my next row in the table would be: > > FirstID SecondID > 1 5 > > How would I go about doing this? I've been looking thru Kevin > Yank's book > "Build Your Own Database Driven Website Using PHP & MySQL", > its pretty good > on the whole but updating two tables simultaneously seems to > be lacking > detail. > > I hope I've made this clear enough, I may have repeated > myself there but I > was wanted to make sure that what I've written is cleary understood. > > Thank you in advance for any help - I'm lost! > > Graeme :) > > > Public Sub House() > > On Error Resume drink > > If Pint.empty = True Then > Pint.refill > Else > Pint.drink > End if > > stomach.add Pint > > MsgBox " I've had .... " & stomach.count & " Pints" > MsgBox "VERY DRUNK" > > End Sub > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php