samedi 30 décembre 2017

php - How to delete row of table from sql database upon check of checkbox?

I have an HTML table created with Bootstrap with checkboxes fetching data from an sql database and if the checkbox is checked, the row is copied to another table below that one with js.

Also, how would I add the row to a new sql database? I know this requires php, but am not sure where to put it.

How would I delete the copied row from the mySQL database? Thanks in advance.

<html>
    <head>
        <title> Dashboard</title>
        <link type="text/css" href="css/bootstrap.min.css" rel="stylesheet">
        <link type="text/css" href="css/bootstrap-table.css" rel="stylesheet">
        <link type="text/css" href="css/font-awesome.css" rel="stylesheet">
        <link rel="stylesheet" type="text/css" href="custom.css">
</head>
<body>
<div class="container">
    <div class="col-md-12">
        <div class="panel panel-success">        
            <div class="panel-body">
                <div class="row">
                    <div class="col-md-12">

                        <table  id="table"
                                data-show-columns="true"
                                data-height="460">
                        </table>
                    </div>
                </div>
            </div>              
        </div>

    </div>
</div>
            <table id="duplicate" class="table table-striped">
      <thead>
        <tr>
          <th>
            #
          </th>
          <th>
            registrant
          </th>
        </tr>
      </thead>
      <tbody>
      </tbody>
    </table>
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-table.js"></script>
<script type="text/javascript">
    var x=0;
     var $table = $('#table');
             $table.bootstrapTable({
                  url: 'list-leads.php',
                  search: true,
                  pagination: true,
                  buttonsClass: 'primary',
                  showFooter: true,
                  minimumCountColumns: 2,
                  columns: [{
                      data: '',
                      title: '',
                      checkbox: true,
                  },{
                      field: 'num',
                      title: '#',
                      sortable: true,
                  },{
                      field: 'registrant',
                      title: 'registrant',
                      sortable: true,
                  },  ],
 }).on('check.bs.table', function(row, element) {
  if (x <= 10) { $('#duplicate > tbody:last-child').append('<tr><td>' + element.num + '</td><td>' + element.registrant + '</td></tr>');x++;}

             });

</script>
</body>
</html>




Aucun commentaire:

Enregistrer un commentaire