通过sql命令和循环[php][sql]检索php中的编辑值

通过sql命令和循环[php][sql]检索php中的编辑值,php,mysql,arrays,loops,Php,Mysql,Arrays,Loops,基本上我有一个仓库ID($srid),它有一个或多个类别($cat) //已在数组中创建类别[] 示例:仓库ID1有两个类别。但当用户希望编辑并包含另一个类别时,这组编码将允许新值通过比较覆盖旧值-array_diff(): 我的储藏室链接到另一个名为Asset($Aid)的表。 随着仓库id的更改,将显示新的数据字段 示例: 资产1拥有仓库ID1,因此由2个类别组成 如上所述,这将导致显示和添加两个数据字段(例如:价格和日期),存储在数据库中,并能够在单独的view_asset.php页面中查

基本上我有一个仓库ID($srid),它有一个或多个类别($cat)

//已在数组中创建类别[]

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

我的储藏室链接到另一个名为Asset($Aid)的表。 随着仓库id的更改,将显示新的数据字段

示例:

资产1拥有仓库ID1,因此由2个类别组成

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

当用户希望编辑资产1时,出现了我的问题。用户将库存更改为

仓库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时,这组代码将调用相关数据字段。例如,如果用户在仓库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; }
我相信要获得编辑后的值,需要执行SQL并循环我的$cat id。 我甚至不知道如何开始。有什么想法吗/

$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; }
        }
    } 
}
如果类别为false,则创建另一个函数:

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;
        }
    }
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;
        }
    }