Update multiple tables : many-to-many relation

1234567

New Member
Need help in updating the tablesI have array of data coming from a form which I'm inserting in my DB. I have 5 tables
  • product
  • filter
  • product_filter
  • heater
  • product_heater
Im able to put the data in the "product", "filter" & "heater" tables but i dont know how to put data inside the "product_filter" & "product_heater" table. Any help or direction to any tutorials is appreciated.My Tables structure:product
  • id int(5)
  • product text
  • cost text
  • details text
filter
  • id int(5)
  • filter text
  • imgpath text
product_filter
  • id int(5)
  • id_product int(5)
  • id_filter int(5)
heater
  • id int(5)
  • heater text
  • imgpath text
product_heater
  • id int(5)
  • id_product int(5)
  • id_heater int(5)
I want to have
  • many-to-many relation between product & heater
  • many-to-many relation between product & Filter
Here is the code : \[code\]PHP Syntax (Toggle Plain Text)// Product data Update$name = mysql_real_escape_string($_POST['product']);$cost = mysql_real_escape_string($_POST['cost']);$details = mysql_real_escape_string($_POST['details']);$sql_title = "INSERT INTO product ( id , product , cost , details , ) VALUES ( NULL , '$name' , '$cost' , '$details')";if (!mysql_query($sql_title,$con)) { die('Error: ' . mysql_error()); }echo "records for product added<br />"; // Filter update// This is the array which is coming from the form/* filtername Array ( [0] => ehiem [1] => Hagan [2] => Rena [3] => jobo ) filterimg Array ( [0] => img1.jpg [1] => img2.jpg [2] => img3.jpg [3] => img4.jpg )*/$filtername = mysql_real_escape_string($filtername);$filterimgpath = mysql_real_escape_string($filterimg);$combined_array = array_combine($filtername, $filterimgpath);$values = array();foreach ($combined_array as $filtername => $filterimgpath){ $values[] = "('$filtername', '$filterimgpath')";}$sql = "INSERT INTO filter (filter , imgpath) VALUES " . implode(', ', $values);//echo $lastid = mysql_insert_id()."<br />";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "records added<br />";//Product Filter Update table // This is where Im stuck. Not able to even think of anything....// heater update// This is the array which is coming from the form/* heatername Array ( [0] => ehiem [1] => Dolphin [2] => Rena [3] => jobo ) heaterimg Array ( [0] => img1.jpg [1] => img2.jpg [2] => img3.jpg [3] => img4.jpg )*/$heatername = mysql_real_escape_string($heatername);$heaterimgpath = mysql_real_escape_string($heaterimg);$combined_array = array_combine($heatername, $heaterimgpath);$values = array();foreach ($combined_array as $heatername => $heaterimgpath){ $values[] = "('$heatername', '$heaterimgpath')";}$sql = "INSERT INTO heater (heater , imgpath) VALUES " . implode(', ', $values);//echo $lastid = mysql_insert_id()."<br />";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "records added<br />";//Product heater Update table // This is where Im stuck. Not able to even think of anything....\[/code\]my question is : how to update product_filter & product_heater tables ?
 
Top