PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I've posted on similar stuff before, but I can't seem to make something work for this. This time however, I made a visio diagram to assist anyone who would help.
What I have done so far is when you edit an incense, it queries the database for the current types of sizes and puts it into a multiple select box:
What I need to do is figure out a way to make some of the option tags have SELECTED in them if there is a corrosponding ProductID and CategoryID in the INCENSE SIZE database.
This seems like it should be simple, and I may well figure it out here soon... but I thought that the talented people here at PHPDN might think of it faster than I.
I mean how would the code to determine that go? Im trying to figure out how the database queries would work and how to code the whole thing. Displaying the results from the SIZE table is easy, but determining which ones are in the INCENSE_SIZE table and then highliting the proper entries in the select box is not as easy.
$query2 = "SELECT * FROM INCENSE_SIZE WHERE ProductID = '" . $ProductID . "' AND SizeID = '".$SizeID."'";
$result2 = mysql_query($query2) or die('Query failed: ' . mysql_error());
$row2 = mysql_fetch_assoc($result2);
$query3 = "SELECT * FROM CATEGORY WHERE Parent = '8' ORDER BY CategoryID ASC";
$result3 = mysql_query($query)3 or die('Query failed: ' . mysql_error());
echo "<tr align=left><td>Category: </td><td><select name=\"CategoryID\">\n";
while ($row3 = mysql_fetch_assoc($result3)) {
$message = "<option value=\"" . $row3['CategoryID'] ."\"";
if ($row3['SizeID'] == $row3['SizeID']) { $message = $message . " SELECTED >"; }else{$message = $message . ">";}
$message = $message . $row3['Name'] . "</option>\n";
echo $message;
}
echo "</select><br /></td>\n";
This is close I think. The only thing is that $row will return multiple rows. I need to figure out how to cycle through each of these rows to determine if the current SizeID matches any of the ones in INCENSE_SIZE.
I'm thinking that after this is submitted I should first drop all of the entries in INCENSE SIZE where ProductID = the product id for that item then insert the ones that were submitted. Does that sound reasonable? Or is there a better way?
ED The problem I see is that every time you edit it, you're going to lose all the QOH and price data.... how would I find out which ones need to be droped and which ones need to be added? ... this is getting tough!