Blogger Information
Blog 49
fans 0
comment 4
visits 41667
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
使用软删除技术,来实现对员工信息中的记录删除操作
过儿的博客
Original
752 people have browsed it

test.php

test.php

实例

<?php
$id = $_GET['id'];
$name = $_GET['name'];
$pdo = new PDO('mysql:host=127.0.0.1;dbname=php','root','root');
//用更新操作来达到软删除的效果
$sql1 = 'UPDATE `staff` SET `is_show`=0 WHERE `id`=:id';
$stmt = $pdo->prepare($sql1);

$stmt->execute(['id'=>$id]);
echo "已经删除了名为".$name."的人员。正在跳转!";
?>
<script>
   setTimeout("location.href='staff_list.php'",2000);
</script>

运行实例 »

点击 "运行实例" 按钮查看在线实例


staff_list.php

实例

<?php
  $pdo = new PDO('mysql:host=127.0.0.1;dbname=php','root','root');
  $sql='SELECT * FROM `staff` WHERE `is_show`=1';
 $stmt = $pdo->prepare($sql);
$stmt->execute();
$staffs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$pdo = null;
$tableTitle = '员工信息表';
$total = count($staffs);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title><?php echo $title; ?></title>
    <style>
        table,th,td {
            border: 1px solid #666;
            padding: 8px;
        }
        table {
            border-collapse: collapse;
            width: 80%;
            text-align: center;
            margin: 30px auto;
        }
        thead tr:first-of-type {
            background-color: lightblue;
        }

        tbody tr:hover {
            background-color: #efefef;
        }

        table > caption {
            font-size: 1.2rem;
            margin-bottom: 15px;
        }
        table + p {
            text-align: center;
        }

        button:hover {
            cursor: pointer;
            background-color: lightblue;
        }

        /*添加按钮给个特殊样式*/
        #add {
            height: 25px;
            width: 90px;
            position: absolute;
            left: 650px;
            top: 40px;
        }

    </style>
</head>
<body>
<button onclick="location.href='#'" id="add">添加</button>


<table>
    <caption>
        <?php
        echo '<span style="color:red">' . $tableTitle . '</span>';
        ?>
    </caption>
    <thead>
    <tr>
        <th>编号</th>
        <th>姓名</th>
        <th>年龄</th>
        <th>性别</th>
        <th>职务</th>
        <th>手机</th>
        <td>入职</td>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>

    <!--foreach()替代语法-->
    <?php foreach($staffs as $staff) : ?>
        <tr>

            <td><?php echo $staff['id']; ?></td>
            <td><?php echo $staff['name']; ?></td>


            <td><?php echo $staff['age']; ?></td>

            <!--if()替代语法-->
            <td>
                <?php if($staff['sex'] == 1) : ?>
                    男
                <?php else: ?>
                    女
                <?php endif; ?>
            </td>


            <!--如果只是简单的输出变量可以使用php短标签语法-->
            <td><?=$staff['position']?></td>
            <td><?=$staff['mobile']?></td>

            <td>
                <?php
                echo date('Y/m/d',$staff['hiredate']);
                ?>
            </td>

            <td>
                <button onclick="location.href='#'">编辑</button>
                <button onclick='location.href="test.php?id=<?php echo $staff['id']; ?>&name=<?php echo $staff['name']?>"'><span style="color:red">删除</span></button>
            </td>

        </tr>
    <?php endforeach;?>

    </tbody>
</table>
<p>总计:
    <?php echo $total;  ?>
    人</p>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

 

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post