I'm trying to get the delete button on this generated table to work (deleting the database record and deleting the row from the view). The button is being generated through the echo statement in the for loop.
我正在尝试让这个生成的表上的删除按钮工作(删除数据库记录并从视图中删除行)。该按钮是通过for循环中的echo语句生成的。
PHP code spitting out the view:
PHP代码吐出视图:
<?php
//Waitlist for Nobel Floorplans
$sth = $db->prepare("SELECT id, first_name, last_name FROM wlist");
$sth->execute();
$results = $sth->fetchAll();
$wishlistArray[] = null;
foreach ($results as $result) {
echo "<tr><td>".$result['first_name']."</td><td>".$result['last_name']."</td><td><button class=\"delete_class\" id=\"".$result['id']."\" >DELETE</button></td></tr>";
}
?>
The bottom of this PHP page, is this javascript f(x):
这个PHP页面的底部是这个javascript f(x):
<script>
$(".delete_class").click(function(){
var del_id = $(this).attr('id');
$.ajax({
type:'POST',
url:'delete_page.php',
data: {delete_id : del_id},
success: function (data) {
if (data) {
tx.executeSql('DELETE FROM wlist WHERE id = ?', [delete_id], success, error);
}
else { // DO SOMETHING
}
}
});
});
</script>
The problem with the above code, is that the URL 'delete_page.php" isn't being referred to, and nothing's being deleted from the database.. that, and the "success: function(data) isn't being called at all..
上面代码的问题是没有引用URL“delete_page.php”,并且没有从数据库中删除任何内容..而且,“成功:函数(数据)根本没有被调用” ..
I have the "delete_page.php" in the same folder as the PHP file containing all the above code. This file has this code:
我在包含所有上述代码的PHP文件所在的文件夹中有“delete_page.php”。这个文件有这个代码:
<?php
$id = $_POST['delete_id'];
$query = "delete from nobel_waitlist where ID = $id";
?>
It would also be great to know how to AJAX delete that row in that view as well as deleting the database record..
知道如何在该视图中删除该行以及删除数据库记录也很棒。
1 个解决方案
#1
0
An Alternative Way. I don't know about executeSql
function, that's why i've given a simple alert
box.
另类方式。我不知道executeSql函数,这就是为什么我给了一个简单的警告框。
<script>
$('.delete_class').click(function(){
var del_id= $('.delete_class').val();
$.ajax({url:"delete_page.php?delete_id="+del_id,cache:false,success:function(result){
alert("Data Deleted");
}});
});
</script>
delete_page.php
<?php
$id = $_GET['delete_id'];
$query = "DELETE FROM nobel_waitlist WHERE ID=:id";
$queryResult = $db->prepare($query);
$queryResult->execute(array(':id' => $id));
?>
#1
0
An Alternative Way. I don't know about executeSql
function, that's why i've given a simple alert
box.
另类方式。我不知道executeSql函数,这就是为什么我给了一个简单的警告框。
<script>
$('.delete_class').click(function(){
var del_id= $('.delete_class').val();
$.ajax({url:"delete_page.php?delete_id="+del_id,cache:false,success:function(result){
alert("Data Deleted");
}});
});
</script>
delete_page.php
<?php
$id = $_GET['delete_id'];
$query = "DELETE FROM nobel_waitlist WHERE ID=:id";
$queryResult = $db->prepare($query);
$queryResult->execute(array(':id' => $id));
?>