Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.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 使用MySQL、jQuery和Ajax添加或删除表行_Php_Jquery_Mysql_Ajax - Fatal编程技术网

Php 使用MySQL、jQuery和Ajax添加或删除表行

Php 使用MySQL、jQuery和Ajax添加或删除表行,php,jquery,mysql,ajax,Php,Jquery,Mysql,Ajax,我有一个使用MySQL和jQuery从表中删除行的脚本。现在我也需要插入行。我应该如何修改代码 index.php if (mysql_num_rows($result2) > 0) { echo "<table>"; while ($searchIds = mysql_fetch_array($result2)) { echo "<tr class='show'> <td>".$sea

我有一个使用MySQL和jQuery从表中删除行的脚本。现在我也需要插入行。我应该如何修改代码

index.php

if (mysql_num_rows($result2) > 0) {
    echo "<table>";
    while ($searchIds = mysql_fetch_array($result2)) {
        echo "<tr class='show'>
                  <td>".$searchIds["channel_name"]."</td>
                  <td>".$searchIds["customer_id"]."</td>
                  <td>
                      <a class='delete' href='#' id='".$searchIds['id']."' channel_id='".$searchIds["channel_name"]." ".$searchIds["customer_id"]."'>Delete id</a>
                  </td>
              </tr>
          </table>";
    }
    echo "</table>";
}
<table id="myTable">
  <tbody>
    <tr>...</tr>
    <tr>...</tr>
  </tbody>
</table>
php提供了删除行的简单查询。

您可以尝试以下方法:

index.php

if (mysql_num_rows($result2) > 0) {
    echo "<table>";
    while ($searchIds = mysql_fetch_array($result2)) {
        echo "<tr class='show'>
                  <td>".$searchIds["channel_name"]."</td>
                  <td>".$searchIds["customer_id"]."</td>
                  <td>
                      <a class='delete' href='#' id='".$searchIds['id']."' channel_id='".$searchIds["channel_name"]." ".$searchIds["customer_id"]."'>Delete id</a>
                  </td>
              </tr>
          </table>";
    }
    echo "</table>";
}
<table id="myTable">
  <tbody>
    <tr>...</tr>
    <tr>...</tr>
  </tbody>
</table>

...
...
js文件

$(function() {
    $(".delete").click(function(){
                .........
    });
    $(".add").click(function(){
        var element = $(this);
        $.ajax({
          type    : "POST",
          url     : "scripts/add.php",
          data    : { add your variables } 
          success : function(){}
               $('#myTable > tbody:last').append('<tr><td>...</td><td>...</td><td>...</td></tr>');
          });
        return false;
    });
});
$(函数(){
$(“.delete”)。单击(函数(){
.........
});
$(“.add”)。单击(函数(){
var元素=$(此);
$.ajax({
类型:“POST”,
url:“scripts/add.php”,
数据:{添加变量}
成功:函数(){}
$('#myTable>tbody:last')。追加('....');
});
返回false;
});
});

在文件add.php中,您可以返回一个json数组并将其读取到新行。

何时添加该行?我可以看到
delete
按钮,但找不到任何
add
按钮。顺便说一句,你在问如何在MySQL(MySQL_query)或HTML表(jQuery)中插入一行?我在行底部有一个文本输入和
add
按钮。