基本上,我有一个储藏室ID ($srid),它有一个或多个类别($cat)。
//类别已在array[]中生成
例子:库房ID1有两大类。但是,由于用户希望编辑并包含另一个类别,这组编码将允许新值通过比较覆盖旧值- 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);
}
我的仓库链接到另一个名为资产($Aid)的表。当库房id发生更改时,将显示新的数据字段。
示例:
资产1有库存ID1,因此由2类别组成。
如前所述,这将导致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; }
我认为要获得已编辑的值,需要在循环我的$cat id的同时执行SQL。我甚至不知道怎么开始。有什么想法吗?/
发布于 2015-01-30 03:38:17
$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;
}
}
https://stackoverflow.com/questions/28040306
复制相似问题