Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 单击html表格';s删除列';s单元(td=x)_Php_Jquery_Html_Mysql - Fatal编程技术网

Php 单击html表格';s删除列';s单元(td=x)

Php 单击html表格';s删除列';s单元(td=x),php,jquery,html,mysql,Php,Jquery,Html,Mysql,我有一个html表格,其中显示了列客户名称、员工名称和事项,而在我的数据库中,我有id、日期、客户名称、员工、事项列。这不是问题所在。我想删除按钮单击时的行,所以我只添加了一个列delete,其中包含id为“del”的按钮,是的,该列在我的数据库中不存在。现在我想删除表中的行以及相应按钮上的数据库,单击UsingjQuery。我该怎么做? 这就是我迄今为止所尝试的- $(document).ready(function(){ $('#tableresult').on('click', '

我有一个html表格,其中显示了列客户名称、员工名称和事项,而在我的数据库中,我有id、日期、客户名称、员工、事项列。这不是问题所在。我想删除按钮单击时的行,所以我只添加了一个列delete,其中包含id为“del”的按钮,是的,该列在我的数据库中不存在。现在我想删除表中的行以及相应按钮上的数据库,单击UsingjQuery。我该怎么做? 这就是我迄今为止所尝试的-

$(document).ready(function(){   

$('#tableresult').on('click', '#del', (function(){
    var row = $(this).attr('id');
    $(#tableresult).removeRow(row);
});

});
我的html-

<td class="delete_td"><button id="del" btn btn-danger>&times;</button></td>
×;
这是我的html表格代码-

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

                                <th>Client name</th>
                                 <th>Staff name</th>
                                 <th>Matter</th>
                                 <th> Delete</th>
                              </thead>

 <?php
include('db.php');
$sql=mysql_query("select * from newdata");
while($row=mysql_fetch_array($sql))
{
$id=$row['id'];
$clientname=$row['client_name'];
$staff=$row['staff'];
$matter=$row['matter'];

?>
<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"><button id="del" btn btn-danger>&times;</button></td>

</tr>



<?php
}
?>

</tbody>
  <tfoot class="hide-if-no-paging">
    <th>                       </th>
     <th>
        <div class="pagination pagination-centered"></div>
     </th>
    <th>             </th>
    <th>             </th>
  </tfoot>
</table>

客户名称
职员姓名
要紧
删除
你的js应该是

$(document).ready(function () {

    $('#tableresult').on('click', '#del', (function () {
        var row = $(this).attr('id');

        $.ajax({
        type: "GET",
                url: 'http://yoursite_url/delete.php',
                data: {id: row },
                success: function (result) {
                $('#'+row).remove();
            }
        });
    });
});
和delete.php

include 'config.php' // DB Connection
$id = $_GET['id'];
$sql = mysql_query("DELETE FROM TABLE_NAME WHERE id = '$id'");
试试这个

$("#del").click(function () {
            var row = $(this).attr('temp_id');
            $.ajax({
                type: "GET",
                url: 'http://yoursite_url/delete.php',
                data: {id: row},
                success: function (result) {
                    $('#row').remove();
                }
            });
        });
像这样换按钮

<button id="del" temp_id="<?php echo $id; ?>"  class="btn btn-danger">&times;</button>

你应该调用ajax来实现这一点。我不太习惯使用ajax。所以请指导我使用它。你是说每行都有自己的
删除
按钮吗?如果单击,关联的行将从html和数据库中删除?是的。它们有相应的del按钮根据您在整个
tr
标记上应用的代码编辑操作。当它应该在特定列上时。发生的情况是,每当我单击特定表行时,它会自动切换到编辑模式,如果我单击列中的“删除”按钮,也会发生同样的情况,但是不删除任何东西Bro你不认为你只是复制了我的全部代码。我只做了一点小改动,即获取已删除行的id。。如果你觉得对不起。。
<button id="del" temp_id="<?php echo $id; ?>"  class="btn btn-danger">&times;</button>