average american Posted September 12, 2007 Share Posted September 12, 2007 Just to let you know i am new to this PHP stuff So here it goes I need to find a way to get my tables(listings, images) to link together. I have an ID column in my listings table and a LISTING_ID column in my images table the prolbem is i cannot get the id from the listings table to the listing_id in the images table any help is greatly appreciated. by the way here is a part of the code: mysql_query("LOCK TABLES listings, images WRITE"); mysql_query("INSERT INTO images (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"); $result = mysql_query("SELECT MAX(ID) AS LAST_ID FROM listings"); $id = mysql_fetch_array($result); mysql_query("UNLOCK TABLES"); echo "Last ID#" . $id[LAST_ID]; echo "<br>File $fileName uploaded<br>"; Quote Link to comment Share on other sites More sharing options...
recklessgeneral Posted September 12, 2007 Share Posted September 12, 2007 Hi, Assuming the ID column in your listings table has been set up to be auto increment, you can use the mysql_insert_id() function to return the value of the id from the insert into the listings table, then pass that value into the listing_id column when inserting into your images table. Hope this helps, Darren. Quote Link to comment Share on other sites More sharing options...
fenway Posted September 12, 2007 Share Posted September 12, 2007 Hi, Assuming the ID column in your listings table has been set up to be auto increment, you can use the mysql_insert_id() function to return the value of the id from the insert into the listings table, then pass that value into the listing_id column when inserting into your images table. Hope this helps, Darren. And then you don't need to LOCK/UNLOCK the tables. 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.