Manage Relational Tables on Update Page
Hi,
I have a many-to-many relationship between products and categories on an ecommerce site. The relational table, relprodcat contains only the foreign keys ProductID and CategoryID. I have succeeded in using the MRT server behavior to populate the relational table properly from the Product Insert page. Now I'm wrestling with the update page.
I assumed that the MRT can and should be used on the update page as well. The thing I'm having trouble figuring out is how to modify that code to have the update page's multiple select list for category, managed via the MRT relational table, generate the appropriate "selected" attribute as derived from the related records. The code for that list is below:
<?php
do {
?>
<option value="<?php echo $row_ProductCategoryList['CategoryID']?>"<?php if (!(strcmp($row_ProductCategoryList['CategoryID'], (isset($_GET['valid'])?ValidatedField("ProductsUpdate","ProductCategoryID"):$row_WADAProducts['ProductCategoryID'])))) {echo "selected=\"selected\"";} ?>
<?php if (!(strcmp($row_ProductCategoryList['CategoryID'], WA_AB_returnPreSelectValue($WA_PreSelect_RelationalTable_1, $row_ProductCategoryList['CategoryID'])))) {echo "selected=\"selected\"";} ?> ><?php echo $row_ProductCategoryList['CategoryName']?></option>
<?php
} while ($row_ProductCategoryList = mysql_fetch_assoc($ProductCategoryList));
$rows = mysql_num_rows($ProductCategoryList);
if($rows > 0) {
mysql_data_seek($ProductCategoryList, 0);
$row_ProductCategoryList = mysql_fetch_assoc($ProductCategoryList);
}
?>
The problem lies in that the multiple select list must have categories selected on the first run of the page, before the data is changed and run a second time via "post". Therefore the string compareson for
WA_AB_returnPreSelectValue($WA_PreSelect_RelationalTable_1, $row_ProductCategoryList['CategoryID'])
fails as it is not populated until the "post", nor are the validation fields.
In addition, even if I highlight new categories, no changes are made in the relational table. So I can't help thinking that I missing something in the use of this behavior for anything but an insert page. Am I headed down the right path? Am I getting confused on the proper use of this behavior?
A thorough tutorial on using the MRT in many situations would certainly save a ton of confusion. The help file alone is not enough.
Thx,
Mark