如何删除与jquery一个MySQL记录 [英] How to delete a mysql record with jquery
本文介绍了如何删除与jquery一个MySQL记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样以下code表示删除一个MySQL记录,我想改变它,这将是一个AJAX / jQuery的code这样我就可以留在同一个页面后,记录已被删除桌子。 现在,它的工作不错,但它不是在同一页上,我需要刷新页面才能看到结果。这是满code只是一部分。 所有code在一个页面上。
//获得MySQL的结果
//这是一个重复的区域
&其中; TR>
< TD>< PHP的echo $行['身份证']; ?>< / TD>
< TD>< PHP的echo $行['标题']; ?>< / TD>
< TD>< PHP的echo $行[说明]。 ?>< / TD>
< TD>< A HREF =manage.php ID =<?PHP的echo $行['身份证'];?>>删除< / A>
< / TD>
< / TR>
如果((使用isset($ _ GET ['deleteid']))及和放大器;!($ _ GET ['deleteid'] =)及及(使用isset($ _ POST ['删除']))){
$ deleteSQL =的sprintf(DELETE FROM my_table的WHERE ID =%s时,
GetSQLValueString($ _ GET ['deleteid'],INT));
解决方案
< TR>
< TD>< PHP的echo $行['身份证']; ?>< / TD>
< TD>< PHP的echo $行['标题']; ?>< / TD>
< TD>< PHP的echo $行[说明]。 ?>< / TD>
< TD>< DIV CLASS =delete_classID =<?PHP的回声$行['身份证'];?>>删除< / DIV>< / TD>
< / TR>
现在的部分写这个
$(文件)。就绪(函数(){
$(delete_class)。点击(函数(){
VAR del_id = $(本).attr('身份证');
$阿贾克斯({
键入:POST,
网址:delete_page.php,
数据:'delete_id ='+ del_id,
成功:功能(数据){
如果(数据){//做一些事情
}其他{//做一些事情}
}
});
});
});
现在,在delete_page.php页面做到这一点
的$ id = $ _ POST ['delete_id'];
$查询=from表名where ID = $ ID删除;
其余的我希望你知道。希望这有助于
I have this following code that delete a mysql record and I would like to transform it so It would be a ajax/jquery code so I can stay in the same page after the record has been deleted from the table. Now, it working fine but it not on the same page and I need to refresh the page to see the result. This is only a part of the full code. All the code in on one page.
//get the mysql results
//this is a repeated region
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['title']; ?></td>
<td><?php echo $row['description']; ?></td>
<td><a href="manage.php?id=<?php echo $row['id']; ?>">Delete</a>
</td>
</tr>
if ((isset($_GET['deleteid'])) && ($_GET['deleteid'] != "") && (isset($_POST['delete']))) {
$deleteSQL = sprintf("DELETE FROM my_table WHERE id=%s",
GetSQLValueString($_GET['deleteid'], "int"));
解决方案
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['title']; ?></td>
<td><?php echo $row['description']; ?></td>
<td><div class="delete_class" id="<?php echo $row['id']; ?>">Delete</div></td>
</tr>
Now in the section write this
$(document).ready(function(){
$(".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) { // DO SOMETHING
} else { // DO SOMETHING }
}
});
});
});
Now in the 'delete_page.php' page do this
$id = $_POST['delete_id'];
$query = "delete from TABLE NAME where ID = $id";
Rest I hope you know. Hope this helps
这篇关于如何删除与jquery一个MySQL记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文