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


    直接上代码,查看上一篇中插入的数据

    <?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);
    ?>
  • 相关阅读:
    自动化运维工具Ansible
    svn服务
    关于nagios系统下使用shell脚本自定义监控插件的编写以及没有实时监控图的问题
    企业级监控nagios实践
    centos6 下FastDFS 在storage节点上nginx的fastdfs-nginx-module 模块编译出现的问题
    分布式文件系统FastDFS
    运维的各个阶段
    用php做一个简单的注册用户功能
    ttttttttttt
    exclude和include当中/**和/*区别
  • 原文地址:https://www.cnblogs.com/snowbaby-kang/p/4435584.html
Copyright © 2020-2023  润新知