管理者リストを表示する PHP 開発企業 Web サイトのチュートリアル

私たちのフレームワークでは、管理者管理をクリックすると、表示プロセス中に、変更と削除を追加するためのリンクが表示されます。クリックして変更と削除を追加すると、次のようなさまざまな機能を実行できます

。図に示すように

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ステートメントを記述します

データベースに接続します

ユーザーテーブルの情報をクエリし、 ID に従って逆順にソートし、SQL ステートメントを実行します。以下の while ループを使用してデータベースを取得します。情報はフロントエンド ページに出力されます

: 変更と削除の後には、 ID の削除と変更は項目の削除などの条件付きである必要があるため、条件がない場合、どの情報が削除されたかに関係なく、プログラムはエラーを報告します

したがって、変更と削除は、パラメータ id 。modifyu.php と deluser.php の 2 つのファイルから 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>
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!