Jump to content

Update Options From Multiple Select


son

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...