php - JQuery-Tabledit 一次只更新一列(我的代码有什么问题)
问题描述
我正在使用 JQuery-Tabledit 来更新 MySQL 表。
我面临的问题是,当我更新第一列的单元格值时,第二列的相同行值消失了。
我无法弄清楚我在这里做错了什么。
这是我的 JQuery-Tabledit 代码
$('#example1').Tabledit({
url: 'logic-edit-delete.php',
editButton: false,
deleteButton: false,
columns: {
identifier: [0, 'id'],
editable: [[4, 'Status', '{"": "Select","P": "Present", "PL": "Planed Leave", "UPL": "UnPlaned Leave", "WO": "Week Off", "COff": "Comp Off", "PH": "Public Holiday", "UPHD": "UnPlaned Half Day", "PHD": "Planed Half Day", "LWP": "Leave Without Pay"}'], [5, 'Leavetype', '{"": "Select","SL": "Sick Leave", "CL": "Casual Leave"}']]
},
和 PHP 代码来更新我的 SQL 表
<?php
include('db-connect.php');
$input = filter_input_array(INPUT_POST);
if ($input['action'] === 'edit')
{
$sql = "UPDATE attendance SET Status ='" . $input['Status'] . "', Leavetype ='" . $input['Leavetype'] . "'" ." WHERE id='" . $input['id'] . "'";
mysqli_query($con,$sql);
}
if ($input['action'] === 'delete')
{
mysqli_query($con,"DELETE FROM attendance WHERE id='" . $input['id'] . "'");
}
mysqli_close($mysqli);
echo json_encode($input);
?>
解决方案
发生这种情况是因为您每次都尝试更新两列。您只需要根据以下条件进行更新:
if(isset($input['Status']) && !empty($input['Status'])) {
$sql = "UPDATE attendance SET Status ='" . $input['Status'] . "' WHERE id='" . $input['id'] . "'";
} else if(isset($input['Leavetype']) && !empty($input['Leavetype'])) {
$sql = "UPDATE attendance SET Leavetype ='" . $input['Leavetype'] . "' WHERE id='" . $input['id'] . "'";
}
推荐阅读
- plone - id 属性中的 TALES 表达式
- uwp - XAML 中的 ObservableCollection 项目数量
- jquery - 通过 Jquery 从 Gmail 中的电子邮件中获取所有信息
- arrays - 如何在 Powershell 中将函数的结果添加到数组中
- asp.net-core - 从 html 转换为 pdf 时,iTextSharp LGPLv2.Core 无法在 rtl 中显示阿拉伯语
- c# - 使用按钮单击 C# 表单暂停和恢复图表和文本框的更新
- javascript - 授权重定向后更改浏览器的 URL
- python - 如何使用 JSON 文件作为使用 Python 的 MS Azure 文本分析的输入?
- java - Java - 在另一个类中无法识别的用户属性
- amazon-web-services - 当您拥有私有 NPM 包时,如何使用 CLI 部署到 Elastic Beanstalk?