duangao8359 2018-10-26 12:44
浏览 64

删除php页面(不是数据库)中的表行,并且在重新加载页面后无法显示它

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

  • 写回答

1条回答 默认 最新

  • douhe6255 2018-10-26 15:17
    关注

    @User10 : (1) Your js at ajax, data:{user_id:user_id}..where's user_id from your table, cause it's just id (2) better put dataType: "json" (at ajax)

    评论

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装