通过 sql 命令检索 php 中的编辑值并循环 [php] [sql]
retrieve edit values in php through sql command and loop [php] [sql]
基本上我有一个库房 ID ($srid),它有 1 个或多个类别 ($cat)。
//分类已经做了数组[]
示例:Stockroom 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) 的 table。
随着库房 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; }
我相信要获得编辑后的值,需要 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;
}
}
基本上我有一个库房 ID ($srid),它有 1 个或多个类别 ($cat)。
//分类已经做了数组[]
示例:Stockroom 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) 的 table。 随着库房 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; }
我相信要获得编辑后的值,需要 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;
}
}