$mprimarykey = $this->getParam("mprimarykey");
$mforeignkey = $this->getParam("mforeignkey");
if ($doSave == "yes") {
    if (is_array($multiselectfield)) {
        $this->setLog("\n multiselect field Array found with " . count($multiselectfield) . " records");
        foreach ($multiselectfield as $ext_table_name) {
            $fieldname = $mprimarykey[$ext_table_name];
            if (strlen($this->getParam($fieldname)) > 0) {
                $fieldvalue = $this->getParam($fieldname);
            } else {
                $fieldvalue = $this->getParam("insertid");
                $this->setLog("\n insert id :" . $fieldvalue);
            }
            $this->setLog("\n processing field: " . $ext_table_name);
            $q_del = new sqlQuery($this->getDbCon());
            $q_del->query("delete from " . $ext_table_name . " where " . $fieldname . "='" . $fieldvalue . "'");
            $q_del->free();
            $q_ins_new = new sqlQuery($this->getDbCon());
            if (is_array($multiselectvalues[$ext_table_name])) {
                $this->setLog("\n multiselectvalues field Array found with " . count($multiselectvalues[$ext_table_name]) . " records");
                foreach ($multiselectvalues[$ext_table_name] as $value) {
                    $q_ins_new->query("insert into " . $ext_table_name . " ({$fieldname}, " . $mforeignkey[$ext_table_name] . ") values ('" . $fieldvalue . "', '" . $value . "')");
                    $this->setLog("\n" . $q_ins_new->getSqlQuery());
                }
            }
            $q_ins_new->free();
        }
    }
}
$this->setLog("\n --- End mydb.formatMultiSelectField ");
$this->setLogRun(false);