Re: more about Last_insert_id

From: Date: Thu, 25 Jan 2001 03:29:19 +0000
Subject: Re: more about Last_insert_id
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-36556@lists.php.net to get a copy of this message
$sql1 = "insert into firsttable (firstname, lastname) values('Jack','Chan')"; $resultsql1 = mysql_query($sql1); Add ... or die(mysql_error()) to the end of that line. $sqlLastID = "select LAST_INSERT_ID() from firsttable"; $resultlast = mysql_query($sqlLastID); Add the same thing here. $FirstLast = mysql_result($resultlast,0,0); $sql2 = "insert into secondtable (FirsttableID,secfirstname, seclastname) values('$FirstLast','Jacky','Chany')"; $resultsql2 = mysql_query($sql2); And here as well. $sqlLastIDsec = "select LAST_INSERT_ID() from secondtable"; $resultlast2 = mysql_query($sqlLastIDsec); And here. $secondLast = mysql_result($resultlast2,0,0); $sql3 = "insert into Thirdtable (SecondTableID,FirsttableID,Thirdfirstname, Thirdlastname) values('$secondLast','$FirstLast','Steve','Chan')"; $resultsql3 = mysql_query($sql3); Everywhere you have mysql_query() $sqlLastIDthird = "select LAST_INSERT_ID() from Thirdtable"; $resultlast3 = mysql_query($sqlLastIDthird); $ThirdLast = mysql_result($resultlast3,0,0); -- Visit the Zend Store at http://www.zend.com/store/ Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm

« previous php.general (#36556) next »