更新更改现有记录
Update change existing records
在这里,我有带复选框的树视图。我的问题是如何为等于 'y' 的选中复选框和等于 'n' 的未选中复选框设置条件。我必须在数据库中更新 chekbox 的值,该值是活动列,包含两个值,即 'y' 和 'n'。我在 javaScript 中使用 AJAX。应该在数据库中选中复选框将获得 'y',未选中复选框将获得 'n'。但是现在,我目前只是在数据库中保存等于 'y' 的选中复选框。任何人都有建议,最好的方法是什么?供您参考,我正在使用 treeview Kendo UI.
update.php
function deleteTemplate(){
global $ehorsObj;
$employeeID = $_SESSION['employeeID'];
$propertyID = $_SESSION['propertyID'];
$id = (isset($_POST['id']) ? $_POST['id'] : '');
$progid = (isset($_POST['progid']) ? $_POST['progid'] : '');
$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() ";
$ehorsObj->ExecuteData($sqlAdd, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
$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() ";
$ehorsObj->ExecuteData($sqlAddLog, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
}}
AJAX JavaScript
//AJAX call for button
$("#primaryTextButton").kendoButton();
var button = $("#primaryTextButton").data("kendoButton");
button.bind("click", function(e) {
var test = $("#dropdown").data("kendoDropDownList").value();
if(test == ""){
KendoAlert("Please select position");//dropdown
}
else{
$.ajax({
url: "../DesignationProgramTemplate/getTempJson.php",
type: "POST",
data: {
method: "addTemplate" ,
id: test,
progid: array
},
success: function () {
KendoAlert('Success'); }});
}
});
您可以轻松获取复选框是否被选中(例如,参见 this),并在您的 ajax 中发送复选框的名称以及值(true/false).
<input type='checkbox' name='checkbox1' class='my-checkboxes'/>Checkbox 1
<script>
$(document).ready(
function () {
$(".my-checkboxes").on('change', function () {
let checkboxIsChecked = ($(this).is(':checked'));
let checkboxName = $(this).attr('name');
//do your ajax post based on the checkbox name and value
console.log(checkboxIsChecked, checkboxName);
});
}
);
</script>
在这里,我有带复选框的树视图。我的问题是如何为等于 'y' 的选中复选框和等于 'n' 的未选中复选框设置条件。我必须在数据库中更新 chekbox 的值,该值是活动列,包含两个值,即 'y' 和 'n'。我在 javaScript 中使用 AJAX。应该在数据库中选中复选框将获得 'y',未选中复选框将获得 'n'。但是现在,我目前只是在数据库中保存等于 'y' 的选中复选框。任何人都有建议,最好的方法是什么?供您参考,我正在使用 treeview Kendo UI.
update.php
function deleteTemplate(){
global $ehorsObj;
$employeeID = $_SESSION['employeeID'];
$propertyID = $_SESSION['propertyID'];
$id = (isset($_POST['id']) ? $_POST['id'] : '');
$progid = (isset($_POST['progid']) ? $_POST['progid'] : '');
$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() ";
$ehorsObj->ExecuteData($sqlAdd, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
$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() ";
$ehorsObj->ExecuteData($sqlAddLog, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
}}
AJAX JavaScript
//AJAX call for button
$("#primaryTextButton").kendoButton();
var button = $("#primaryTextButton").data("kendoButton");
button.bind("click", function(e) {
var test = $("#dropdown").data("kendoDropDownList").value();
if(test == ""){
KendoAlert("Please select position");//dropdown
}
else{
$.ajax({
url: "../DesignationProgramTemplate/getTempJson.php",
type: "POST",
data: {
method: "addTemplate" ,
id: test,
progid: array
},
success: function () {
KendoAlert('Success'); }});
}
});
您可以轻松获取复选框是否被选中(例如,参见 this),并在您的 ajax 中发送复选框的名称以及值(true/false).
<input type='checkbox' name='checkbox1' class='my-checkboxes'/>Checkbox 1
<script>
$(document).ready(
function () {
$(".my-checkboxes").on('change', function () {
let checkboxIsChecked = ($(this).is(':checked'));
let checkboxName = $(this).attr('name');
//do your ajax post based on the checkbox name and value
console.log(checkboxIsChecked, checkboxName);
});
}
);
</script>