Florida web design - did not change; invisibility will still be deleted
did not change; invisibility will still be deleted and reinserted). When updating data in an M:N relationship, you will usually simply delete the old data, and insert the updated/new data. $sql = DELETE FROM char_power_link WHERE char_id = $cid ; $result = mysql_query($sql) or die(mysql_error()); if ($powers != ) { $val = ; foreach ($powers as $key => $id) { $val[] = ( $cid , $id ) ; } $values = implode( , , $val); $sql = INSERT IGNORE INTO char_power_link (char_id, power_id) . VALUES $values ; $result = mysql_query($sql) or die(mysql_error()); } This brings you to the Enemies data, where not only do you have to maintain referential integrity, but you have to worry about updating rows where the ID can be present in either of the two linking columns. You must maintain the reverse referential integrity. $sql = DELETE FROM char_good_bad_link . WHERE good_id = $cid OR bad_id = $cid ; $result = mysql_query($sql) or die(mysql_error()); if ($enemies != ) { $val = ; foreach ($enemies as $key => $id) { $val[] = ( $cid , $id ) ; } $values = implode( , , $val); if ($align == good ) { $cols = (good_id, bad_id) ; } else { $cols = (bad_id, good_id) ; } $sql = INSERT IGNORE INTO char_good_bad_link $cols . VALUES $values ; $result = mysql_query($sql) or die(mysql_error()); } How did you deal with referential integrity? It turns out that it takes care of itself when you follow the same method you employed when updating the char_power_link table. By simply running the same DELETE query you ran when deleting a character, and then immediately running the same INSERT query you ran when creating a new character, you ensure that only one set of rows exists to match up each character to his/her enemy. It s simple, elegant, and it works! 299 Building Databases
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.