【问题标题】:to delete particular row from database as well as html table on corresponding button click从数据库中删除特定行以及相应按钮单击的 html 表
【发布时间】:2016-01-09 14:42:07
【问题描述】:

我想从我的 html 以及我的数据库中删除特定的行,单击该行中的相应按钮。到目前为止,我只能从我的 html 表中删除它,但我不知道如何从我的数据库中删除它。我知道它会涉及 ajax 代码,但我不太熟悉使用它,所以请帮忙
这是我的html-

<div id="divGrid">
                             <table class="footable" data-filter="#filter" id="tableresult">
                               <thead>

                                <th>Client name</th>
                                 <th>Staff name</th>
                                 <th>Matter</th>
                                 <th> Delete</th>
                              </thead>
                             <tr id="<?php echo $id; ?>" class="edit_tr">

<td class="edit_td" >
<span id="client_<?php echo $id; ?>" class="text"><?php echo $clientname; ?></span>
<input type="text" value="<?php echo $clientname; ?>" class="editbox" id="client_input_<?php echo $id; ?>" /&gt;
</td>

<td class="edit_td">
<span id="staff_<?php echo $id; ?>" class="text"><?php echo $staff; ?></span> 
<input type="text" value="<?php echo $staff; ?>" class="editbox" id="staff_input_<?php echo $id; ?>"/>
</td>

<td class="edit_td">
<span id="matter_<?php echo $id; ?>" class="text"><?php echo $matter; ?></span> 
<input type="text" value="<?php echo $matter; ?>" class="editbox" id="matter_input_<?php echo $id; ?>"/>
</td>

<td class="delete_td"><input type="button" id="del"  class="btn btn-danger" value="&times;"></input></td>

</tr>
and here is my jquery-
$(document).ready(function () {
    $('input[type=button]').click(function () {
        $(this).parent().parent().remove();
        if ($('#tableresult tr').length < 2) {
            $('#divGrid').empty();
            $('#divGrid').html("All item removed");
        }

    });

});

这样我就可以在上面实现我的代码。我怎么做? 请检查一下这有什么问题-

$(document).ready(function () {
    $('input[type=button]').click(function () {
       var row = $(this).attr('id');
       $.ajax({
             type: "POST",
             url: 'delete.php',
             data: {id: row},
              success: function (result) {
        $(this).parent().parent().remove();
        if ($('#tableresult tr').length < 2) {
            $('#divGrid').empty();
            $('#divGrid').html("All item removed");
        }
      }
    });
 });
});

php代码-

【问题讨论】:

  • 你想做什么?您的专栏有类delete_td。您可以将此作为列的参考。

标签: php jquery html mysql button


【解决方案1】:

因为你的 td 有一个类引用,你可以使用它

$('.delete_td') <!--- references the entire td

您还可以使用该列是按钮的父级这一事实并检索所有包含按钮的列。但我认为上面的代码回答了这个问题

【讨论】:

  • 不,我想从数据库中删除特定行以及相应按钮单击该行中的 html 表
  • 实际上我得到了以前的参考资料..这只是一个愚蠢的错误,但我不知道如何从数据库中删除该行到目前为止我只能从 html 表中删除它。我正在编辑我的代码请帮我解决这个问题
  • 您的问题要求引用代码执行的 html 表中的列。无论如何,您可以使用 tr 的 id,因为我假设它是记录的 id。然后,您可以运行 sql 删除与 id 匹配的数据库中的记录
  • 我知道,但我不太熟悉使用 ajax ..而且我知道这涉及 ajax..所以你能帮忙吗?
  • developphp.com/video/JavaScript/… 是一个好的开始。 Ajax 是一种方法,但实际上你可以在没有 ajax 的情况下做到这一点
猜你喜欢
  • 1970-01-01
  • 2016-09-03
  • 1970-01-01
  • 1970-01-01
  • 2018-06-08
  • 1970-01-01
  • 2016-01-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多