您的位置:首页 > 编程语言 > PHP开发

php+sql创建本地项目详细步骤3——查看与删除数据库数据

2015-04-17 17:40 706 查看
直接上代码,查看上一篇中插入的数据

<?php
include 'dblink.php';
$sql="select * from shoes_jd_wx";
$rs=mysql_query($sql); //执行sql语句,获得结果集。
$arr=array();
while($ro=mysql_fetch_array($rs)){//从结果集中获取一行记录作为关联数组。
$arr[]=$ro;
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8" />
<title>女鞋管理列表</title>
</head>
<?php include 'header.php';?>
<body>
<div class="main">
<table class="table table-bordered table-center">
<tr>
<th>图片名称</th>
<th>京东价格</th>
<th>邮费</th>
<th>操作</th>
</tr>
<?php
if($arr){foreach($arr as $shoes){
?>
<tr data-id="<?php echo $shoes['id']; ?>">
<td><?php echo $shoes['picname']; ?></td>
<td><?php echo $shoes['jdprice'];?></td>
<td><?php echo $shoes['postfree'];?></td>
<td><a href="updateshoes.php?id=<?php echo $shoes['id']; ?>" class="btn btn-link editshoes">编辑</a>
<a href="javascript:void(0);" data-id ="<?php echo $shoes['id']; ?>" class="btn btn-link delshoes">删除</a></td>
</tr>
<?php }}?>
</table>
</div>
<?php include 'footer.php';?>
<script>
$(document).ready(function(){
$(".delshoes").click(function(){
var id = $(this).data("id");
$.ajax({
type: 'POST',
url: "deleteAction.php",
data: {"id":id},
dataType: 'json',
success: function(result){
if(result == 1){
alert("删除成功");
}else{
alert("删除失败");
}
window.location.href = 'http://localhost/shoes/shoesmanage.php'
}
});
})
})
</script>
</body>
</html>


删除数据:在上面的代码中已经可以看到,这里的删除全部使用ajax

deleteAction.php

<?php include 'dblink.php';

$id=$_POST['id'];
$sql="delete from shoes_jd_wx where id='$id'";

if(mysql_query($sql)){
echo json_encode(1);
}else{
echo json_encode(0);
}
mysql_close($dblink);
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐