-2

guys, I am doing a project in PHP where I should display in a page data from the database and remove from the page(not database) if I checkbox them using ajax. any source or link that could help me understand better this? thank you!! p.s all I've done so far is deleting the data from the page and database at the same time

 while($row = mysqli_fetch_array($result))
{

  <tr id="<?php echo $row["id"]; ?>" >
  <td><?php echo $row["id"]; ?></td>
  <td><?php echo $row["name"]; ?></td>
  <td><?php echo $row["surname"]; ?></td>
  <td><input type="checkbox" name="id[]" class="delete" value="<?php echo $row["id"]; ?>" /></td>

**deleting method **

$.ajax({
 url:'delete.php',
 method:'POST',
 data:{id:id},
 success:function() {
  for(var i=0; i<id.length; i++){
   $('tr#'+id[i]+'').css('background-color', '#ccc');
   $('tr#'+id[i]+'').fadeOut('slow');
  • 1
    If you just want to remove the data from the page then there is no need for an ajax call. https://stackoverflow.com/questions/11553768/remove-table-row-after-clicking-table-row-delete-button –  Oct 24 '18 at 15:51
  • thanks man that's really helpful, but I don't want the data to come back in my page if I reload it – Albi Meta Oct 25 '18 at 07:41

1 Answers1

0

If you're not deleting from the database then using AJAX isn't needed at all; use a javascript event listener that is triggered by a "delete selected" button or by the checkboxes themselves to remove the row from the table

iGuy
  • 42
  • 3
  • thanks, that's what I did, but I think I need ajax to not display the data I deleted again after I reload the page, any idea how can I do that? I think I should add a boolean row in my table in the database and if is checked don't display the row. could anyone help? – Albi Meta Oct 25 '18 at 08:21
  • 1
    if that's the case then yes you will need another column in your table to act as a flag to hide it from reappearing on refresh. Inside your delete.php file your query should update the record's "hide" column to a 1 and change your query that loads the data by applying (or appending) a where clause for "hide" column = 0 – iGuy Oct 25 '18 at 16:49