Hi, Its almost working. it does insert the number of items I have selected. however, what its doing is inserted the same ID for all entries. After my test if I select all categories from the list, the ID which is being written to the table is the very first ID from those that I select.
For example is my database table consider of:
CategoryID
6
7
8
9
10
and if I select all the above in my multi-select list then it will create 5 records in the catalog table BUT all with ID 6 being stored.
Here is the code for the insert and the code for the html form:
Chris
<?php
for ($x=0; $x<sizeof($_POST['selectedCats']); $x++) {
?>
<?php
if (($_SERVER["REQUEST_METHOD"] == "POST") && (isset($_SERVER["HTTP_REFERER"]) && strpos(urldecode($_SERVER["HTTP_REFERER"]), urldecode($_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"])) > 0) && isset($_POST)) {
$InsertQuery = new WA_MySQLi_Query($ecartdb);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "`catalog`";
$InsertQuery->bindColumn("CatalogCategoryID", "i", "".((isset($_POST["selectedCats"]))?implode(",",$_POST["selectedCats"]):"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("CatalogProductID", "i", "".$_SESSION['ProductID'] ."", "WA_DEFAULT");
$InsertQuery->saveInSession("CatalogID");
$InsertQuery->execute();
$InsertGoTo = "product-manage.php";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
$InsertQuery->redirect($InsertGoTo);
}
?>
<?php
}
?>
<select name="selectedCats[]" style="width: 260px;" multiple="" class="chosen-select">
<?php
while(!$rsCategory->atEnd()) { //dyn select
?>
<?php
if ("".($rsCategory->getColumnVal("CategoryParentID")) ."" != "0") { // WebAssist Show If
?>
<optgroup label="<?php echo($rsCategory->getColumnVal("CategoryID")); ?>">
<?php
} // ("".($rsCategory->getColumnVal("CategoryParentID")) ."" != "0")
?>
<option value="<?php echo($rsCategory->getColumnVal("CategoryID")); ?>"><?php echo($rsCategory->getColumnVal("CategoryName")); ?></option>
</optgroup>
<?php
$rsCategory->moveNext();
} //dyn select
$rsCategory->moveFirst();
?>
</select>