zoukankan      html  css  js  c++  java
  • PHP删除数据

    1.查看数据

    <body>
    <h1>显示info信息</h1>
    <table width="100%" border="1" cellpadding="0" cellspacing="0">
    <tr>
    <td>代号</td>
    <td>姓名</td>
    <td>性别</td>
    <td>民族</td>
    <td>生日</td>
    <td>操作</td>
    </tr>

    <?php
    $db = new MySQLi("localhost","root","123","mydb");  造连接对象
    $sql = "select * from 表名";      查询表中的所有数据
    $result = $db->query($sql);    执行sql语句
    $arr = $result->fetch_all();
    foreach($arr as $v)    遍历
    {
    //修改性别
    $sex = $v[2]?"男":"女";  性别等于男的情况下输出男,反之输出女

    //修改民族
    $sql1 = "select name from nation where code='{$v[3]}'";
    $r1 = $db->query($sql1);
    $a1 = $r1->fetch_row();

    echo "<tr>
    <td>{$v[0]}</td>
    <td>{$v[1]}</td>
    <td>{$sex}</td>
    <td>{$a1[0]}</td>
    <td>{$v[4]}</td>
    <td><a href='del.php?code={$v[0]}' onclick="return confirm('确认删除么?')">删除</a></td>   不能都是双引号,转义字符
    </tr>";                                            onclick不仅可以写函数,可以写任何JS代码
    }
    ?>

    </table>
    </body>

    <script type="text/javascript">  出现一个警告对话框
    //confirm("确定删除么");
    </script>

    2.处理

    <?php
    $code = $_GET["code"];    在主表中的删除传送方式使用的get,所以这里用get传送

    $db = new MySQLi("localhost","root","123","mydb");  造新的链接
    $sql = "delete from info where code='{$code}'";       写sql语句,因为是代号不会重复,所以查找代号等于定义的code
    if($db->query($sql))     执行sql语句
    {
    跳转页面
    header("location:main.php");    删除成功返回到主表的页面,location:地址。
    //echo "<script>window.location.href='main.php'</script>";  href=后面加地址。
    }
    else
    {
    echo "删除失败!";
    }

  • 相关阅读:
    SharePoint 2010 At Work--SharePoint 2010 Tab Page 创建选项卡页面
    SharePoint At Work----Hyperlinks in the Data View Web Part
    SharePoint At Work----SharePoint Data View Web Part
    SharePoint 2010 品牌化和自定义--母版页
    面对复杂的或者高并发的或者海量数据的问题
    提升算力的程序设计
    关于方案,关于设计,关于思考
    关于测试
    数据资源管理程序的功能以及设计的总结
    如何做软件设计
  • 原文地址:https://www.cnblogs.com/zqld/p/6769425.html
Copyright © 2011-2022 走看看