文章目录[隐藏]
<?php$act=$_GET['act'];$id=$_GET['id'];switch($act){case "del";$del=$dbc->prepare("delete from naszt where 1=1 and id=?");if($del->execute(array($id))){ echo "<script>";echo "$(function() {";echo "$('.del').click(function() {";echo " $('#'+$(this).attr('id')).remove()";echo "})";echo "})";echo "</script>"; }else{ echo '<script>alert("由于网络原因,删除失败,请重试!");</script>'; }}?><?php $se<i style="color:transparent">本文来源gaodai$ma#com搞$$代**码)网8</i><strong>搞代gaodaima码</strong>lectSpecialContent=$dbc->prepare("select * from naszt");$selectSpecialContent->execute();?><table align="center" cellspacing="0" cellpadding="0"><tr><th>专题名称</th><th>专题类型</th><th>发表时间</th><th>发表ip</th><th>操作</th></tr><?php while($row=$selectSpecialContent->fetch()){ ?><tr>"><td><?php echo $row['ztname']?></td><td><?php echo $row['zttype']?></td><td><?php echo $row['zttime']?></td><td><?php echo $row['publiship']?></td><td><button>">查看</button><button>">修改</button><button class='del'>">" >删除</button></td></tr><?php }; ?></table>
请问大神,这样写,php的查询是否是执行了两次?
<script type=”text/javascript”>
$(function() {
$(‘.del’).click(function() {
$(‘#’+$(this).attr(‘id’)).remove();
});
});
</script>
这段js就是删除当前的tr,但是我觉的$selectSpecialContent=$dbc->prepare(“select * from naszt”);
$selectSpecialContent->execute(); 这句SQL查询又被执行了一次
回复讨论(解决方案)
是的,你的 js 代码会做错误的操作
是的,你的 js 代码会做错误的操作
那能给个思路吗?
把你的 8 到 14 行去掉就是普通的删除记录的代码
如果是 ajax 就该在删除后退出,并不能输出 script 标记
把你的 8 到 14 行去掉就是普通的删除记录的代码
如果是 ajax 就该在删除后退出,并不能输出 script 标记
没有用到ajax呢
从头到尾只有一次查询操作,就算你执行删除操作,那也是一次查询操作。如果你删除的时候不想执行查询下面的内容,那你就要使用ajax 来操作了