PHP development corporate website tutorial showing administrator list
In our framework, when we click on administrator management, the administrator should be displayed. During the display process, links for adding modifications and deletions will be given. By clicking to add modifications and deletions, various functions can be completed
As shown in the picture below
When you click to add an administrator, you will go to the add administrator page. Modifications and deletions will go to the respective pages
Of course, we need to fetch the information from the database and then display it
The code is as follows:
<?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>
We write the php tag at the beginning of the page
Write the php statement inside
Connect to the database
Query the information of the user table, sort it in reverse order according to the id, and then execute the sql statement. We use the while loop below to retrieve the database information and output it to the front-end page
Note: Modifications and deletions are followed by an id because deletion and modification must be conditional, such as which one to delete. If there are no conditions, the program does not know which one to delete. If there is a piece of information, an error will be reported
So our modification and deletion will output a parameter id Get the id from the two files modifyu.php and deluser.php and then perform the operation