I have a page called fetch as belllow :
$statement = $connection->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$data = array();
$filtered_rows = $statement->rowCount();
foreach($result as $row){
$sub_array = array();
$sub_array[] = $row["id"];
$sub_array[] = $row["first_name"];
$sub_array[] = $row["last_name"];
$sub_array[] = '<input type="checkbox" name="confirm" id="'.$row["id"].'" class="btn btn-danger btn-xs delete"></input>';
$data[] = $sub_array;
}
$output = array(
"draw" => intval($_POST["draw"]),
"recordsTotal"=> $filtered_rows,
"recordsFiltered"=> get_total_all_records(),
"data" => $data
); echo json_encode($output);
and I have a function in the index page that calls the delete page :
$(document).on('click', '.delete', function(){
var user_id = $(this).attr("id");
if(confirm("Are you sure you want to delete this?"))
{
$.ajax({
url:"delete.php",
method:"POST",
data:{user_id:user_id},
success:function(data)
{
alert(data);
dataTable.ajax.reload();
}
});
}
else
{
return false;
}
});
and the delete page looks like this :
if(isset($_POST["user_id"])){
$statement = $connection->prepare(
"DELETE FROM users WHERE id = :id"
);
$result = $statement->execute(
array(
':id' => $_POST["user_id"]
)
);
if(!empty($result))
{
echo 'Data Deleted';
}}
also in the database, I have a table with 4 columns id, first_name, last_name, and check_in (boolean). All I want to do is hide the data displayed from the database if I checkbox them, even after I reload the page. till now I just can delete them. or if I add this function:
$(document).ready(function(){
$("#myTable").on('click','.del',function(){
$(this).closest('tr').hide();
});
});
I can hide them but they came back after I reload the page