Unless there are a very large number of categories it would seem quite efficient and easier to code to delete and rebuild the link (lookup) table.
I would approach it a bit dfferently. In pseudo code.
Form:
Code:
// the array will be used to to build checkboxes (or drop down menus)
Get all category names and ids from category table
while category {
Save in associative array: key=category-id, value=category
}
Get all products
while product {
get product category link-list
while category {
create numeric array
}
// for each category
foreach category {
build checkboxes (or drop down menus)
using the category array as the template
and the product-category array as values (checked)
}
output product row
}
Output form buttons and close form
Form processing:
Code:
Create new table (link_new)
foreach product {
foreach category {
create sql query
}
write link records
}
delete old link file
rename "link_new" to "link"
Bookmarks