Jump to content

Update Options From Multiple Select


son
 Share

Recommended Posts

When creating a new product I create a n-n relationship and insert relevant rows of product id with category id in association table. The code is:

	if(count($category) > 0)	{	$sql = "INSERT INTO productCat (category_id, product_id) VALUES ";		foreach ($category as $v)		{    	$sql .= "('$v', '$id'),";		}	$sql = substr($sql,0,-1);	}					if ($sqlRes = mysqli_query ($dbc, $sql))	{	echo "<p>The product has been added!<br />";				echo "<span class=\"small\"><a href=\"products.php\"><< Go back</a></span></p>";				include('inc/footer.php');				exit;				}

That is all working fine. Now I am working on a form to update all product data. The normal stuff is all fine, but am not sure what is best to do with the product -category relationship. If the multiple select has not been changed I do not want to run a query, but if it has then the relevant query should be run. Am a bit confused as for obvious reasons former entries that do not apply any more would need to be removed (if user selected completely different categories from multiple select). Also, I make the entries from database automatically selected, so the user can see hightlighted the current categories before making a choice. Therefore I cannot really do a check if category is set. How would I do this otherwise?Son

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...