Adding or deleting table rows with MySQL, jQuery and Ajax

lingo

I have a script that removes row from table with MySQL and jQuery. Now I need to insert rows too. How should I modify the code?

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>";
}

.js

$(function() {
    $(".delete").click(function(){
        var element = $(this);
        var del_id = element.attr("id");
        var info = 'deleteid=' + del_id;
        var channel_id = element.attr("channel_id");
        if(confirm("Delete?\n\n" + channel_id)){
            $.ajax({
                type    : "POST",
                url     : "scripts/delete.php",
                data    : info,
                success : function(){}
            });
            $(this).parents(".show")
                .animate({ backgroundColor: "#003" }, "slow")
                .animate({ opacity: "hide" }, "slow");
        }
        return false;
    });
});

And delete.php has simple query for deleting row.

Marcos Navarro

You can try this:

index.php

<table id="myTable">
  <tbody>
    <tr>...</tr>
    <tr>...</tr>
  </tbody>
</table>

js file

$(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;
    });
});

In your file add.php you can return a json array and read it to the new row .

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

AJAX/Jquery not deleting row from MySQL table

From Dev

Calculate automatically in a table using jquery when adding or deleting rows

From Dev

Adding/Deleting table rows based on Select value

From Dev

Adding rows to table using jquery

From Dev

Adding rows to table using jquery

From Dev

mysql table not decreased in size after deleting rows

From Dev

Deleting rows from 3 tables in MySQL table

From Dev

Script for deleting table rows not working in MySQL & PHP

From Dev

jquery ajax adds mysql rows at the end of the table-repeating

From Dev

adding multiple rows in mysql table based on an array

From Dev

Deleting rows in HTML table

From Dev

Adding new rows to table on clicking button in JQuery

From Dev

jQuery, adding multiple table rows is not working correctly

From Dev

Adding table rows and column dynamically with jQuery

From Dev

Efficiently deleting rows from one table where not matching another [MySQL]

From Dev

Deleting many rows from a big table MySql 5.5.46

From Dev

MySQL: deleting rows based on a condition with data from another table and NO JOIN

From Dev

Deleting Mysql rows with checkbox

From Dev

jQuery manipulating table rows from ajax response

From Dev

adding <tr> to table using jquery + keep jquery function on added rows

From Dev

Adding and deleting rows in dynamic table in Asp.net mvc razor view

From Dev

Deleting multiple rows from a table

From Dev

Dynamically added table rows not deleting

From Dev

Deleting multiple rows from a table

From Dev

adding to mysql and deleting on the same page

From Dev

Adding, editing, deleting rows of the grid using Struts2 jQuery Grid plugin

From Dev

Adding Jquery Confirm For Deleting Record

From Dev

Bootstrap adding rows to a table

From Dev

Dynamically adding rows to a table

Related Related

  1. 1

    AJAX/Jquery not deleting row from MySQL table

  2. 2

    Calculate automatically in a table using jquery when adding or deleting rows

  3. 3

    Adding/Deleting table rows based on Select value

  4. 4

    Adding rows to table using jquery

  5. 5

    Adding rows to table using jquery

  6. 6

    mysql table not decreased in size after deleting rows

  7. 7

    Deleting rows from 3 tables in MySQL table

  8. 8

    Script for deleting table rows not working in MySQL & PHP

  9. 9

    jquery ajax adds mysql rows at the end of the table-repeating

  10. 10

    adding multiple rows in mysql table based on an array

  11. 11

    Deleting rows in HTML table

  12. 12

    Adding new rows to table on clicking button in JQuery

  13. 13

    jQuery, adding multiple table rows is not working correctly

  14. 14

    Adding table rows and column dynamically with jQuery

  15. 15

    Efficiently deleting rows from one table where not matching another [MySQL]

  16. 16

    Deleting many rows from a big table MySql 5.5.46

  17. 17

    MySQL: deleting rows based on a condition with data from another table and NO JOIN

  18. 18

    Deleting Mysql rows with checkbox

  19. 19

    jQuery manipulating table rows from ajax response

  20. 20

    adding <tr> to table using jquery + keep jquery function on added rows

  21. 21

    Adding and deleting rows in dynamic table in Asp.net mvc razor view

  22. 22

    Deleting multiple rows from a table

  23. 23

    Dynamically added table rows not deleting

  24. 24

    Deleting multiple rows from a table

  25. 25

    adding to mysql and deleting on the same page

  26. 26

    Adding, editing, deleting rows of the grid using Struts2 jQuery Grid plugin

  27. 27

    Adding Jquery Confirm For Deleting Record

  28. 28

    Bootstrap adding rows to a table

  29. 29

    Dynamically adding rows to a table

HotTag

Archive