Jump to content

linking tables


average american

Recommended Posts

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>";

 

Link to comment
https://forums.phpfreaks.com/topic/68952-linking-tables/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/68952-linking-tables/#findComment-346721
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/68952-linking-tables/#findComment-347059
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.