单击删除按钮删除数据库条目.数据通过数据库中的循环显示


Delete database entry on click of delete button. The data is showed through loop from database

点击fb共享按钮时,会出现一个新的小窗口/div,询问与朋友共享或私人共享等选项,这与我想要显示的相同。我的数据通过数据库中的循环显示,我希望如果单击循环元素,则会出现一个新的div来确认删除该条目,并在退出时单击确认按钮从数据库中删除该条目。

这里有一个想法:

    start loop here
    <input type='button' value='Delete' onclick='deletefunction(id_from_loop);'>
    end loop here

    <script>
    function deletefunction(id_to_delete)
    {
var x = confirm("Delete record ?");
            if (x == true) {
                //do the deleting routine (ajax, etc) here, then refresh the page.
            } else {
                return false;
            }
    }
    </script>

在页面中添加这样的代码。

捕获PHP操作

<?php
if($_GET['delete_id']){
  //sql query to delete your record
}
?>

HTML删除链接

<a href="http://example.com?delete_id=<?php echo $data['id'];?>" onclick="return doconfirm('<?php echo $data['id'];?>'">  </a>

Javascript确认弹出窗口:

<script>
function doconfirm(Id){
    var res = confirm("Are you sure you want to delete this element?");
    if(res === true){
      // will go to link
      retrun true;
    }else{
        alert("You just same me man! Thank you.");
    }
}
</script>