my other attempt is :
which groups the parent categories together
but when i then want to display any child categories which are grouped by parents, what its doing is from the screenshot: is repeating the name of one parent category and its not displaying all child categories (only one occurance)
<select name="selectedCats[]" style="width: 260px;" multiple="" class="chosen-select">
<?php
while(!$rsParentCategories->atEnd()) { //dyn select
?>
<option value="<?php echo($rsParentCategories->getColumnVal("CategoryID")); ?>"><?php echo($rsParentCategories->getColumnVal("CategoryName")); ?></option>
<?php
$rsParentCategories->moveNext();
} //dyn select
$rsParentCategories->moveFirst();
?>
<?php
$rsChildCategories = new WA_MySQLi_RS("rsChildCategories",$ecartdb,0);
$rsChildCategories->setQuery("SELECT * FROM categories WHERE CategoryParentID = ?");
$rsChildCategories->bindParam("i", "".($rsParentCategories->getColumnVal("CategoryID")) ."", "-1"); //colname
$rsChildCategories->execute();
?>
<?php
while(!$rsChildCategories->atEnd()) {
?><optgroup label="<?php echo($rsParentCategories->getColumnVal("CategoryName")); ?>">
<option value="<?php echo($rsChildCategories->getColumnVal("CategoryID")); ?>"><?php echo($rsChildCategories->getColumnVal("CategoryName")); ?></option></optgroup>
<?php
$rsChildCategories->moveNext();
}
$rsChildCategories->moveFirst(); //return RS to first record
?>
</select>

