I have a chunk of code I use to control entries that go into "relationship" tables .
The table's purpose is to record which people have what categories
- so it's one to many
data is input via dyanmic checkboxes on the page
right now, on submit, I delete all entries for that person, then do an INSERT of the submitted entries
it works, no problem
if($ref_id) {
$sql = "DELETE FROM customer_type_matches WHERE cust_id='$ref_id'";
$result=runsql($sql,'delete services','','');
//run sql function
foreach ($serv_clicks as $key => $row)
{
$sql = "INSERT INTO customer_type_matches (cust_id, cust_type_id) VALUES ('$ref_id','$row')";
$result=runsql($sql,'update services','','');
//run sql function
}
}
is there a better way of doing this?
I know I could make an array of current entries then update or insert based on live checkbox entries... but that would end up as more queries and more code