更新更改现有记录

在这里,我有带有复选框的树视图。我的问题是如何为选中的复选框设置等于“y”的条件,如果未选中的复选框等于“n”。我必须在数据库中更新 chekbox 的值,该值是活动列,包含两个值,即“y”和“n”。我在 javaScript 中使用 AJAX。应该选中复选框将获得“y”,未选中复选框将在数据库中获得“n”。但现在,我目前只是在数据库中保存等于“y”的复选框。任何人都有建议,最好的方法是什么?供您参考,我正在使用 treeview Kendo UI。


更新.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);

}}

http://img.mukewang.com/61e136f80001663709930259.jpg

DIEA
浏览 119回答 1
1回答

素胚勾勒不出你

您可以轻松获取是否选中了复选框(例如,请参见this),并在您的 ajax 中发送复选框的名称以及值(true/false)。<input type='checkbox' name='checkbox1' class='my-checkboxes'/>Checkbox 1<script>&nbsp; &nbsp; $(document).ready(&nbsp; &nbsp; &nbsp; &nbsp; function () {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(".my-checkboxes").on('change', function () {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let checkboxIsChecked = ($(this).is(':checked'));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let checkboxName = $(this).attr('name');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //do your ajax post based on the checkbox name and value&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(checkboxIsChecked, checkboxName);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; );</script>
打开App,查看更多内容
随时随地看视频慕课网APP