Example:
DB Result: 1,2,3,4
Form Result: 1,3,4,5
If you were to compare the two you would find that you had to add ID 5 and delete ID 2. I am trying to figure out just how to code that.
Code: Select all
<?PHP
$Submit = $_GET['Submit'];
$Sizes = $_POST['Sizes'];
$dbh=mysql_connect ("localhost", "*****", "*******") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ('guttersg_ggoods');
$query2 = "SELECT `SizeID` FROM `INCENSE_SIZE` WHERE `ProductID` = '9'";
$result2 = mysql_query($query2) or die('Query failed: ' . mysql_error());
if ($Submit) {
echo "Sizes before: <br />";
var_dump($Sizes);
echo "<br /><br />";
while ($row2 = mysql_fetch_assoc($result2)) {
echo "Looking for SizeID: ".$row2['SizeID']."...<br />\n";
foreach ($Sizes as $i => $s) {
if($s == $row2['SizeID']) {
echo " Found size: $i[$s] in result. ID: $i Value: $s<br /><br />\n";
unset($Sizes[$i]);
}/*else{
echo "Adding value to array for deletion. Value: ".$row2['SizeID']."<br /><br />\n";
$delkey[] = $row2['SizeID'];
}*/
}
}
echo "Sizes after: <br />";
var_dump($Sizes);
echo "<br /><br />";
}else{
?>Code: Select all
<form action="<?PHP $_SERVER['PHP_SELF'] ?>?Submit=1" method="post">
<select multiple name="Sizes[]">
<option value="1">Size 1</option>
<option value="2">Size 2</option>
<option value="3">Size 3</option>
<option value="4">Size 4</option>
<option value="5">Size 5</option>
</select>
<input type="submit">
</form>