我将在这里为以下代码进行解释。我有两个表,分别是tblHrsPositionProgramTemplate
和tblHrsPositionProgramTemplateLog
。
处理流程为:
tblHrsPositionProgramTemplate
中的取消勾选ID(未选中的复选框)。 tblHrsPositionProgramTemplateLog
中并设置为'n'。tblHrsPositionProgramTemplate
中tblHrsPositionProgramTemplate
和tblHrsPositionProgramTemplateLog
中勾选id(已选中的复选框)。因此,问题是我的tblHrsPositionProgramTemplateLog
的ID为空。有人知道我的代码有什么问题吗?我正在尝试多种方法,但结果仍然相同。
PHP
function updateTemplate(){
global $ehorsObj;
$employeeID = $_SESSION['employeeID'];
$propertyID = $_SESSION['propertyID'];
$positionTemplateID = (isset($_POST['positionTemplateID']) ? $_POST['positionTemplateID'] : '');
$id = (isset($_POST['id']) ? $_POST['id'] : '');
$progid = (isset($_POST['progid']) ? $_POST['progid'] : '');
$active = (isset($_POST['active']) ? $_POST['active'] : '');
$unProgId = (isset($_POST['unProgId']) ? $_POST['unProgId'] : '');
//solution 1
$sqlReadTable = "SELECT * FROM tblHrsPositionProgramTemplate
WHERE hrsPositionID = '" . $id . "' ";
$GetResult = $ehorsObj->FetchData($sqlReadTable, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
while ($row = $GetResult->fetch()){
if (in_array($row['programID'], $unProgId)) { //Checking for untick id(unchecked checkbox) in table tblHrsPositionProgramTemplate
$sqlInsertlog = "INSERT INTO tblHrsPositionProgramTemplateLog
SET positionTemplateIDLog = '" . $row['positionTemplateIDLog'] . "',
positionTemplateID = '" . $row['positionTemplateID'] . "',
programID = '" . $row['programID'] . "',
hrsPositionID = '" . $row['hrsPositionID'] . "',
propertyID = '" . $row['propertyID'] . "',
employeeID = '" . $row['employeeID']. "',
dateTimeEmployee = NOW() ,
active = 'n' "; //If there is untick id, insert id into tblHrsPositionProgramTemplateLog and set as 'n'.
$ehorsObj->ExecuteData($sqlInsertlog, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
}
}
//Delete current id in tblHrsPositionProgramTemplate (because to avoid duplicate display in view)
$sqlDelete = "DELETE FROM tblHrsPositionProgramTemplate
WHERE hrsPositionID = '".$id."' ";
$ehorsObj->ExecuteData($sqlDelete, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
for($x=0; $x< sizeof($progid); $x++ )
{
$positionTemplateID = $ehorsObj->EHORS_PK("tblHrsPositionProgramTemplate");
$sqlAdd = "INSERT INTO tblHrsPositionProgramTemplate
SET positionTemplateID = '" . $positionTemplateID . "',
programID = '" . $progid[$x] . "',
hrsPositionID = '" . $id . "',
propertyID = '" . $propertyID . "',
employeeID = '" . $employeeID . "',
dateTimeEmployee = NOW(),
active = 'y'"; //Insert again tick id(checked checkbox) in tblHrsPositionProgramTemplate and tblHrsPositionProgramTemplateLog.
$ehorsObj->ExecuteData($sqlAdd, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
if (in_array($progid[x], $unProgId)){
//do nothing
}else{
$positionTemplateIDLog = $ehorsObj->EHORS_PK("tblHrsPositionProgramTemplateLog");
$sqlAddLog = "INSERT INTO tblHrsPositionProgramTemplateLog
SET positionTemplateIDLog = '" . $positionTemplateIDLog . "',
positionTemplateID = '" . $positionTemplateID . "',
programID = '" . $progid[$x] . "',
hrsPositionID = '" . $id . "',
propertyID = '" . $propertyID . "',
employeeID = '" . $employeeID . "',
dateTimeEmployee = NOW(),
active = 'y'"; //masuk dlm log id yg tick
$ehorsObj->ExecuteData($sqlAddLog, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
}
}}