【问题标题】:retrieve edit values in php through sql command and loop [php] [sql]通过 sql 命令检索 php 中的编辑值并循环 [php] [sql]
【发布时间】:2015-01-20 08:03:35
【问题描述】:

基本上,我有一个库房 ID ($srid),其中包含 1 个或多个类别 ($cat)。

//已经在数组中做了类别[]

示例:库房 ID1 有 2 个类别。但是当用户希望编辑和包含另一个类别时,这组编码将允许新值通过比较覆盖旧值 - array_diff() :

function einv_editStockrm($srid,$code,$name,$desc,$remark,$cat)
{
    $Stockroom = einv_getStockrmDetail($srid);
    $oldCat = $Stockroom["einv_stockrm_cat"];
    $oldCatArr = explode(",",$oldCat);
    $newCatArr = explode(",",$cat);
    $resultCatAdd = array_diff($newCatArr, $oldCatArr);
    $resultCatRemove = array_diff($oldCatArr, $newCatArr);
}

我的仓库链接到另一个名为 Asset ($Aid) 的表。 随着库房 ID 的变化,会显示新的数据字段。

示例:

资产 1 具有 stockroom ID1,因此包含 2 个类别

如上所述,这导致 2 个数据字段(例如:价格和日期) 被显示和添加,存储在数据库中并能够在单独的 view_asset.php 页面中查看。

这是我的问题,因为用户希望编辑资产 1。用户将仓库更改为

stockroom ID2,其中包含一个新数据字段(例如:仓库)

这将导致以前的值(价格和日期)被清除,并且视图页面应该只显示这个新的数据字段(仓库)结果。我无法这样做,因此我仍将获得旧值。

这是我在编辑资产中的一些代码。 这些基本上是我的库房 $cat 并检查用户添加了哪一个:

function einv_editAsset
{
if ($stockrmID != $AssetOtherDetail['einv_stockrm_id']) {
        $catCheck = explode(",", $StockrmDetails['einv_stockrm_cat']);
        foreach($catCheck as &$value) {
            if($value == "General Information") {
                $checkGeneral = true;
            } elseif ($value == "Product Information") {
                $checkProduct = true;
            } elseif ($value == "Warranty Information") {
                $checkWarranty = true;
            } elseif ($value == "Sales Parts") {
                $checkSales = true;
            } elseif ($value == "Customer Information") {
                $checkCustomer = true;
            } elseif ($value == "Internal Information") {
                $checkInternal = true;
            } elseif ($value == "Warehouse Information") {
                $checkWarehouse = true;             
            } elseif ($value == "Yearly Reset") {
                $checkYR = true;
            }
        }
    } else {
        $catCheck = explode(",", $AssetOtherDetail['einv_stockrm_cat']);
        foreach($catCheck as &$value) {
            if($value == "General Information") {
                $checkGeneral = true;
            } elseif ($value == "Product Information") {
                $checkProduct = true;
            } elseif ($value == "Warranty Information") {
                $checkWarranty = true;
            } elseif ($value == "Sales Parts") {
                $checkSales = true;
            } elseif ($value == "Customer Information") {
                $checkCustomer = true;
            } elseif ($value == "Internal Information") {
                $checkInternal = true;
            } elseif ($value == "Warehouse Information") {
                $checkWarehouse = true; 
            } elseif ($value == "Yearly Reset") {
                $checkYR = true;
            }
        }
    }

编辑资产 sql:

//start transaction - Utilizes RollBack in the event of an error somewhere midway thereabouts
    base_executeSQL("START TRANSACTION;");
    $editAssetSQL = "UPDATE einv_asset SET einv_asset_code = '" . $code . "', einv_asset_dlogged = '" . $dlogged . "'
    WHERE einv_asset_code = '" . $oldCode . "' ";
    //Checking and executing the query
    if (!base_executeSQL($editAssetSQL)) {
        $continue = false;
        echo $editAssetSQL;
    }

这组代码将在用户检查 $cat 时调用相关数据字段。例如,如果用户在 stockroom id 中添加了一般信息,它将调用一般信息中可用的数据。

if ($checkGeneral == true) {
        $editGeneralSQL = "UPDATE einv_general_information SET einv_ginfo_status = '" . $status . "',
        einv_ginfo_remark = '" . base_addSlashSQL($remark) . "'
        WHERE einv_ginfo_aid = '" . $oldCode . "' ";
        //Check and execute query
        if(!base_executeSQL($editGeneralSQL)) {
            $continue = false;
            echo $editGeneralSQL;
        }
    } else { $continue = true; }

我相信要获得编辑后的值,它需要在循环我的 $cat id 的同时执行 SQL。 我什至不知道如何开始。有任何想法吗? :/

【问题讨论】:

    标签: php mysql arrays loops


    【解决方案1】:
    $get_einv_asset_stockrm_SQL = base_executeSQL($SQL);
    while($General_row = base_fetch_array($get_einv_asset_stockrm_SQL))
    
    if (base_num_rows($get_einv_asset_stockrm_SQL)!= 0)
    {
    
        // General Information category
        if ($checkGeneral == true) {
    
            if(einv_checkStockrmCat($General_row['einv_asset_code'],"General"))
            {   
                $addGeneralSQL="INSERT INTO einv_general_information (einv_ginfo_status,einv_ginfo_remark,einv_ginfo_aid)
                    VALUES ('" . $status . "','" . base_addSlashSQL($remark) . "','" . $General_row['einv_asset_code'] . "')";
    
                //Check and execute query
                if(!base_executeSQL($addGeneralSQL)) {
                    $continue = false;
                    echo $addGeneralSQL;
                }else { $continue = true; }
            }
        } 
    }
    

    如果类别为假,则创建另一个函数:

    function einv_checkStockrmCat
    {
        if($category == "General")
        {
            $generalSQL = "SELECT * FROM einv_general_information WHERE einv_ginfo_aid = '" . $assetcode . "') ";
            $get_einv_asset_stockrm_SQL = base_executeSQL($generalSQL);
            $total = base_num_rows($get_einv_asset_stockrm_SQL);
            if ($total!= 0)
            {
                return true;
            }
            elseif($total== 0)
            {
                return false;
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2017-05-03
      • 1970-01-01
      • 2023-03-17
      • 2015-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-04
      • 2011-05-31
      相关资源
      最近更新 更多