Php 如何传递ID以删除数据库中的数据

Php 如何传递ID以删除数据库中的数据,php,mysql,datatable,server-side,Php,Mysql,Datatable,Server Side,我还在努力学习如何使用数据库服务器 我想寻求有关如何传递数据库/表中删除、添加和编辑列的id值的帮助 这是我的密码: jQuery( document ).ready(function() { var table = jQuery('#example').dataTable({ "bProcessing": true, "sAjaxSource": "server/data2.php", "bPaginate":true,

我还在努力学习如何使用数据库服务器

我想寻求有关如何传递数据库/表中删除、添加和编辑列的id值的帮助

这是我的密码:

jQuery( document ).ready(function() {
var table = jQuery('#example').dataTable({

         "bProcessing": true,
         "sAjaxSource": "server/data2.php",
          "bPaginate":true,
          "sPaginationType":"full_numbers",
          "iDisplayLength": 15,

         "aoColumns": [
                { mData: 'INVOICE' },
                { mData: 'PRODUCT' },
                { mData: 'SIZE' },
                { mData: 'DATE' },
                { mData: 'DDATE' },
                { mData: 'SUPLIER' },
                { mData: 'COST' },
                { mData: 'STATUS' }
        ],
            "columnDefs": [ 
          {   
            "aTargets":[8],  // this your column of action
            "mData": null, 
            "mRender": function(data, type, full){
             return '<div id="container"><a class="btn btn-info btn-sm" href="javascript: void(0);" class="click_'+full[0]+'" title="Click to PRINT">PRINT</a></div>';   // replace this with button 
            }
          }
         ]
});   
我还在学习如何使用数据库

感谢那些能够给出建议的人:)

如何传递ID以删除数据库中的数据

SQL查询字符串在PHP代码中应如下所示:

$sql = 'DELETE FROM invoice WHERE id = <ID>';
然后将结果放在表格中,如下所示:

<table id="example" class="table table-striped table-bordered table-hover" width="100%" cellspacing="0">
    <thead>
    <tr>
        <th>INVOICE</th>
        <th>Product Name</th>
        <th>SIZE</th>
        <th>DATE ORDER</th>
        <th>DATE DELIVER</th>
        <th>SUPPLIER</th>
        <th>COST</th>
        <th>STATUS</th>
        <th>FORM</th>
        <th></th>
    </tr>
    <?php
        foreach ($invoices as $invoice) {
            echo "<tr id='row-{$invoice['id']}'>
                    <td>{$invoice['invoice_number']}</td>
                    <td>{$invoice['product_name']}</td>
                    <td>{$invoice['some_field']}</td>
                    <td>{$invoice['some_other_field']}</td>
                    <td>{$invoice['ect']}</td>
                    // ...
                    <td><button class='delete-btn' id='{$invoice['id']}'>Delete</button></td>
                 </tr>";
        }
    ?>
    </thead>
</table>

单击按钮时会触发此jQuery函数。它获取您单击的对象(按钮)的id属性,然后使用id参数向invoice.php发送post请求-这是您执行删除查询字符串并将此id传递给从请求中获得的where条件的文件。最后,jQuery函数从DOM中删除该行。

服务器端代码在哪里?
$sql = 'DELETE FROM invoice WHERE id = <ID>';
$sql = 'SELECT * FROM invoice';
<table id="example" class="table table-striped table-bordered table-hover" width="100%" cellspacing="0">
    <thead>
    <tr>
        <th>INVOICE</th>
        <th>Product Name</th>
        <th>SIZE</th>
        <th>DATE ORDER</th>
        <th>DATE DELIVER</th>
        <th>SUPPLIER</th>
        <th>COST</th>
        <th>STATUS</th>
        <th>FORM</th>
        <th></th>
    </tr>
    <?php
        foreach ($invoices as $invoice) {
            echo "<tr id='row-{$invoice['id']}'>
                    <td>{$invoice['invoice_number']}</td>
                    <td>{$invoice['product_name']}</td>
                    <td>{$invoice['some_field']}</td>
                    <td>{$invoice['some_other_field']}</td>
                    <td>{$invoice['ect']}</td>
                    // ...
                    <td><button class='delete-btn' id='{$invoice['id']}'>Delete</button></td>
                 </tr>";
        }
    ?>
    </thead>
</table>
$(document).ready(function(){
    $('body').on('click', 'button.delete-btn', function(events){
        let id = $(this).attr('id');
        $.post("invoice.php", {
            id
        });

        $('#row-' + id).remove();
    });
});