php - 创建空表并插入数据

标签 php html mysql

我想创建一个表格来在此处输入代码插入、更新删除

这个想法是用表格替换表单,例如,在填充第一行或动态创建第二行或放置按钮添加行和之后,创建一个仅包含标题和准备插入数据的空行的表格返回写入内容和插入等。 我正在尝试这种方式,但是我无法在列中写入然后进行插入:

<table id="products-table"> 
    <tbody>  
        <tr>       
            <th>Produto</th>       
            <th>Código</th>    
            <th>Quantidade</th>    
            <th>Preço</th>     
            <th>Ações</th>   
        </tr>   
        <tr>       
            <td>&nbsp;</td>    
            <td>&nbsp;</td>    
            <td>&nbsp;</td>    
            <td>&nbsp;</td>    
            <td>         
            <button onclick="RemoveTableRow(this)" type="button">Remover</button>      
            </td>    
        </tr>   
    </tbody>    
    <tfoot>  
        <tr>      
            <td colspan="5" style="text-align: left;">
                <button onclick="AddTableRow()" type="button">Adicionar Produto</button>      
            </td>   
        </tr>   
    </tfoot>    
</table>    

<script>
(function($) {
    AddTableRow = function() {  
    var newRow = $("<tr>");     var cols = "";  
    cols += '<td>&nbsp;</td>';  
    cols += '<td>&nbsp;</td>';  
    cols += '<td>&nbsp;</td>';  
    cols += '<td>&nbsp;</td>';  
    cols += '<td>';  
    cols += '<button onclick="RemoveTableRow(this)" type="button">Remover</button>';
    cols += '</td>';    
    newRow.append(cols);    
    $("#products-table").append(newRow);    
    return false;   
    };
})(jQuery); 
</script> 

但是我疑问,创建一个表格来替换html中的表单有意义吗?

最佳答案

这确实有道理,我建议你看看DataTable这使您能够通过适当的回调等来处理此类用例。唯一的限制是您需要 jQuery。

关于php - 创建空表并插入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56808942/

相关文章:

php - 发布一个空变量 PHP

php - 通过 php 内爆函数格式化 SQL 查询

javascript - 反转空终止字符串的代码

javascript - 使用 Python Flask 自定义 Stripe Checkout

mysql - 使用第二个 INNER JOIN 或在第二个 INNER JOIN 之前对两个表进行 INNER JOIN 的 SQL

c# - 关于mssql和mysql中的select查询以及表名的保留关键字问题

javascript - jquery 在页面加载时设置 href 链接

php - JS和PHP复杂数据之间的桥梁

php - 将 mysql 行添加到表中 href 的末尾

php - Laravel 5.2 [PDOException] SQLSTATE[42000] - 创建两个 auto_increment 主键字段