PHP开发企业网站教程之展示管理员列表

在我们框架里面,当我们点击管理员管理的时候,应该展示管理员,展示的过程中会给出,添加 修改,删除的连接,通过点击添加修改,删除,从而完成各种功能

如下图所示

user.png

当点击添加管理员,到添加管理员页面,修改和删除都是到各自的页面

当然,信息时需要我们从数据库取出来,然后展示

代码如下:

<?php
    require_once('conn.php'); //连接数据库
    $sql = "select * from user order by id desc"; //查询user表中的数据
    $info = mysql_query($sql);
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>展示用户列表</title>
    <style type="text/css">
        .top{height:30px;line-height:30px;float:right;margin-right:15px;}
        .top a{color:red;text-decoration:none;}
        .cont{width:100%;height:300px;float:left;}
        .cont_ct{float:left;}
        table{width:100%;border:1px solid #eee;text-align:center;}
        th{background:#eee;}
        td{width:200px;height:30px;}
    </style>
</head>
<body>
    <div class="top"><a href="addu.php">添加管理员</a></div>

    <div class="cont">
        <table cellspacing="0" cellpadding="0" border="1">
            <tr>
                <th>ID</th>
                <th>用户名</th>
                <th>密码</th>
                <th>操作</th>
            </tr>
            <?php
                //获取表中的数据
                while($row=mysql_fetch_array($info)){
            ?>
            <tr>
                <td><?php echo $row['id'];?></td>
                <td><?php echo $row['username'];?></td>
                <td><?php echo $row['password'];?></td>
                <td>
                    <a href="modifyu.php?id=<?php echo $row['id'];?>">修改</a>
                    <a href="deluser.php?id=<?php echo $row['id'];?>">删除</a>
                </td>
            </tr>
            <?php
                }
            ?>
        </table>
    </div>
</body>
</html>

我们在页面开头写上php标签

内部写上php语句

连接数据库

查询  user 表的信息,根据 id 进行倒排序,然后执行  sql   语句, 我们在下面使用while 循环,来取出数据库信息,并输出到前端页面

注意 :修改 和 删除们在后面都跟着输出了一个  id   因为删除和修改,都是要有条件的,比如删除那条,如果没有条件,程序是不知道删除哪条信息的,就会报错

所以我们的修改删除上都会输出一个参数   id   在modifyu.php 和 deluser.php  俩个文件上进行获取  id  然后在去执行操作

继续学习
||
<?php require_once('conn.php'); //连接数据库 $sql = "select * from user order by id desc"; //查询user表中的数据 $info = mysql_query($sql); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>展示用户列表</title> <style type="text/css"> .top{height:30px;line-height:30px;float:right;margin-right:15px;} .top a{color:red;text-decoration:none;} .cont{width:100%;height:300px;float:left;} .cont_ct{float:left;} table{width:100%;border:1px solid #eee;text-align:center;} th{background:#eee;} td{width:200px;height:30px;} </style> </head> <body> <div class="top"><a href="addu.php">添加管理员</a></div> <div class="cont"> <table cellspacing="0" cellpadding="0" border="1"> <tr> <th>ID</th> <th>用户名</th> <th>密码</th> <th>操作</th> </tr> <?php //获取表中的数据 while($row=mysql_fetch_array($info)){ ?> <tr> <td><?php echo $row['id'];?></td> <td><?php echo $row['username'];?></td> <td><?php echo $row['password'];?></td> <td> <a href="modifyu.php?id=<?php echo $row['id'];?>">修改</a> <a href="deluser.php?id=<?php echo $row['id'];?>">删除</a> </td> </tr> <?php } ?> </table> </div> </body> </html>
提交重置代码
章节
笔记
提问
课件
反馈
捐赠

PHP开发企业网站实战教程