无法检索选定的数组值[php]

时间:2015-01-14 09:48:16

标签: javascript php jquery arrays

生成库房下拉列表

function einv_generateStockrmSelectDropdown($Stockrm,$field,$dropdown) {
    //connect to database
    base_connectDatabase();
    echo "<select id=\"stockrm\" name=\"".$field."[]\" multiple=\"multiple\" style=\"align:left\" class=\"form-control\">";

    if (isset($Stockrm) && ($Stockrm != "")) {
        $stockrmname = einv_getStockrmDetail($Stockrm);
        echo "<option value=\"". $Stockrm ."\">". $stockrmname['einv_stockrm_name'] ."</option>";
    } else {
        $Stockrm = 0;
    }
    $getStockrmSQL = base_executeSQL("SELECT * FROM einv_stockroom WHERE einv_stockrm_id<>" . $Stockrm . " ORDER BY einv_stockrm_name");
    while ($Stockrmdata_row = base_fetch_array($getStockrmSQL)) {
       if (base_num_rows($getStockrmSQL)!= 0) {
           echo "<option value=\"".$Stockrmdata_row['einv_stockrm_id']."\">".$Stockrmdata_row['einv_stockrm_name']."</option>";
       }
    }
    echo "</select>";
    echo "<script src=\"../terms_base/js/jquery.multiple.select.js\">     </script>";

    //Input some codes to split the dropdown and make it into the setSelects. By default, the first time = AutoSelectAll
    if(isset($dropdown) && ($dropdown != "")) { //dropdown = 1;2;3
        $SDDArrays = explode(";", $dropdown);
        $countTrap0 = count($SDDArrays);
        $drop = "$('#stockrm').multipleSelect(\"setSelects\", [";
        $counting = 1;
        foreach ($SDDArrays as &$value) {
            if ($countTrap0 != $counting) {
                $drop .= "'". $value . "',";
            } else {
                $drop .= "'". $value . "'";
            }
            $counting++;
        }
        $drop .= "]);\n";
    } elseif (isset($dropdown)) { //dropdown=
        $drop = "$('#stockrm').multipleSelect(\"uncheckAll\")";
    } else { //
        $drop = "$('#stockrm').multipleSelect(\"checkAll\")";
    }

    echo "<script>\n";
    echo "$(function() {\n";
    echo "".$drop."";
    echo "});\n";
    echo "$(\"#stockrm\").multipleSelect({ onClose: function() {
            document.getElementById('search').click();
        }});\n";
    echo "$(\"#stockrm\").multipleSelect();\n";
    echo "</script>";

    //close the database
    base_closeDatabase();
}


//This function is use to add new stock room
//code = stock room code
//name = stock room name
//desc = stock room description
//remark = stock room remark
//cat = stock room category

添加库房功能

function einv_addStockrm($code,$name,$desc,$remark,$cat)
{
    //connect to database
    base_connectDatabase();
    $User = base_getUserDetail($_SESSION['uID']);

base_executeSQL("INSERT INTO einv_stockroom (einv_stockrm_code, einv_stockrm_name, einv_stockrm_desc, einv_stockrm_remark, einv_stockrm_cat)
VALUES ('" . $code . "', '" . $name . "', '" . $desc . "', '" . $remark . "', '" . $cat . "')");

base_addTransactionLog('Manage Stock Room', 'Add',
"
Stock Room Code = " . $code . " ||
Stock Room Name = " . $name . " ||
Stock Room Description = " . $desc . " ||
Stock Room Remark = " . $remark . " ||
Stock Room Category = " . $cat . "
");
        //go to stock room page
        echo '<script type="text/javascript">' . "\n";
        echo 'window.location="../einventory/stockrm_list.php";';
        echo '</script>';
    //close the database
    base_closeDatabase();
}

修改库房

function einv_editStockrm($srid,$code,$name,$desc,$remark,$cat)
{
    //connect to database
    base_connectDatabase();

    $User = base_getUserDetail($_SESSION['uID']);
    $Stockroom = einv_getStockrmDetail($srid);
    base_executeSQL("UPDATE einv_stockroom
    SET einv_stockrm_code='" . $code . "',
    einv_stockrm_name='" . $name . "',
    einv_stockrm_desc='" . $desc . "',
    einv_stockrm_remark='" . $remark . "',
    einv_stockrm_cat = '" . $cat . "'
    WHERE einv_stockrm_id=" . $srid . "");

    base_addTransactionLog('Manage Stock Room', 'Edit',
    "
    Stock Room Code = " . $code . " ||
    Stock Room Name = " . $name . " ||
    Stock Room Description = " . $desc . " ||
    Stock Room Remark = " . $remark . " ||
    Stock Room Category = " . $cat . "
    ");
        //go to stock room page
        echo '<script type="text/javascript">' . "\n";
        echo 'window.location="../einventory/view_stockrm.php?id='. $srid .'";';
        echo '</script>';



    //close the database
    base_closeDatabase();
}

文件名:add_Stockroom.php和edit_stockroom.php

我有一个名为 Stockroom 的下拉列表,其中显示了一系列值。

示例:

贮藏室

  1. [A]
  2. [B]
  3. [C]
  4. 当用户点击[A]时,它将显示[A]拥有的相关数据字段(显示在库房ddl下方)。

    当用户点击[B]时,会有一个onchange函数,然后显示[B]数据字段(A中的字段被删除并替换为B)。

    我能够添加初始值但是,因为我想编辑并将库房从[A]更改为[B],这将导致存储全新数据,我无法这样做。

    有什么想法吗?

    我相信我必须修改我的编辑库房功能,我需要一组编码,例如

    如果选择了阵列,我必须删除现有数据并根据所选ID添加新数据。

0 个答案:

没有答案