close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

form multi select list insert records

Thread began 6/06/2016 3:34 pm by Christopher West | Last modified 9/12/2016 7:19 pm by Christopher West | 1703 views | 41 replies

Christopher WestCommunity Expert

I need to revisit this and getting working. this is my updated code:

So to recap (I have the functionality working in my Product Create - where upon I can add categories in a multi select list (and they display as pills). On the update page I only have it working in part (the part where it will delete the records from the catalog table and then updates with new ones, on your suggestion).

However I haven't got it working where it would display in the multi-select list the categories that are stored in the catalog table associated with that product.

here are the code blocks: (Im also attaching the php file of the product create page where the categories are working in the multi select list correctly for comparison of code.

php:
<?php

$rsProduct 
= new WA_MySQLi_RS("rsProduct",$ecartdb,1);
$rsProduct->setQuery("SELECT * FROM products WHERE ProductID = ?");
$rsProduct->bindParam("i""".(isset($_GET['ProductID'])?$_GET['ProductID']:"")  ."""-1"); //colname
$rsProduct->execute();
?>
<?php
@session_start();
if(
"" == "")     {
  
$_SESSION["ProductID"] = "".($rsProduct->getColumnVal("ProductID"))  ."";
}
?>



php:
<?php

$rsCatalog 
= new WA_MySQLi_RS("rsCatalog",$ecartdb,1);
$rsCatalog->setQuery("SELECT * FROM `catalog` LEFT JOIN categories ON catalog.CatalogCategoryID = categories.CategoryID WHERE catalog.CatalogProductID = ?");
$rsCatalog->bindParam("i""".(isset($_GET['ProductID'])?$_GET['ProductID']:"")  ."""-1"); //colname
$rsCatalog->execute();
?>
<?php
  
function IsInRecordset($rs,$col,$val) {
    for (
$x=0$x<sizeof($rs->Results); $x++) {
      if (
$rs->Results[$x][$col] == $val) return true;
    }
    return 
false;
  }
?>




php:
<?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)) {
  
$DeleteQuery = new WA_MySQLi_Query($ecartdb);
  
$DeleteQuery->setQuery("DELETE FROM `catalog` WHERE CatalogProductID = ?");
  
$DeleteQuery->bindParam("i","".($_GET['ProductID'])  ."");
  
$DeleteQuery->execute();
  
$DeleteGoTo "";
  if (
function_exists("rel2abs")) $DeleteGoTo $DeleteGoTo?rel2abs($DeleteGoTo,dirname(__FILE__)):"";
  
$DeleteQuery->redirect($DeleteGoTo);
}
?>
<?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""".($_POST["selectedCats"][$x]) ."""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
}
?>




php:
<select name="selectedCats[]" style="width: 260px;" multiple="" class="chosen-select">

                        
        
                          <?php
  
while(!$rsParentCategories->atEnd()) { //dyn select
  
?>
                          <?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();
?>



   <option <?php echo(IsInRecordset($rsCatalog,"CatalogCategoryID",$rsChildCategories->getColumnVal("CategoryID"))?"selected":"");?>></option>


                          <?php
  
if ("".($rsChildCategories->getColumnVal("CategoryParentID"))  ."" "0") {  // WebAssist Show If
?>
                          <option value="<?php echo($rsParentCategories->getColumnVal("CategoryID")); ?>"><?php echo($rsParentCategories->getColumnVal("CategoryName")); ?></option>
                          <?php
  
// ("".($rsChildCategories->getColumnVal("CategoryParentID"))  ."" < "0")
?>
                          <?php
while(!$rsChildCategories->atEnd()) {
?>
                          <option value="<?php echo($rsChildCategories->getColumnVal("CategoryID")); ?>"><?php echo($rsParentCategories->getColumnVal("CategoryName")); ?> - <?php echo($rsChildCategories->getColumnVal("CategoryName")); ?></option>
                          <?php
  $rsChildCategories
->moveNext();
}
$rsChildCategories->moveFirst(); //return RS to first record
?>
                          <?php
  $rsParentCategories
->moveNext();
  } 
//dyn select
  
$rsParentCategories->moveFirst();
  
?>
                        </select>
Attached Files
product-create.php

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...