页面化操作数据库

首先默认选择库test1,01.php中然后用show tables;查询出所有的表,然后用循环依次输出所有的表名,和操作超链接,超链接上对应有该表的信息传到02.php,02.php中,根据接收到的参数,查询到该表,然后用desc 表名,结果循环输出表字段名,再查询出所有字段循环输出对应的值,后面有操作超链接,存有该行数据的信息,传到03.php.03.php可以更改

01.php

<?php
$conn=mysql_connect("localhost","root","111111");
mysql_query("set names utf8",$conn);//设置编码
mysql_query("use test1");//选库
$sql="show tables";
$rs=mysql_query($sql,$conn);
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>列出所有表</title>
</head>
<body>
    <table border=1 width=50%>
        <p>所有的表</p>
        <tr>
            <td>表名</td>
            <td>操作</td>
        </tr>
        <?php
            while($row=mysql_fetch_assoc($rs)){
                echo "<tr>";
                echo "<td>",$row["Tables_in_test1"],"</td>";
                echo "<td>","<a href=02.php?table=".$row["Tables_in_test1"].">编辑</a></td>";
                echo "</tr>";
            }
        ?>
    </table>
</body>
</html>

 02.php

<?php
$conn=mysql_connect("localhost","root","111111");
mysql_query("set names utf8",$conn);//设置编码
mysql_query("use test1");//选库
$table=$_GET['table'];//接收数据
addslashes($table);
$sql="select * from ".$table;
$rs=mysql_query($sql,$conn);
$sql="desc ".$table;
$ziduan=mysql_query($sql,$conn);
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>表中所有的数据</title>
</head>
<body>
<table border=1 width="50%">
    <?php
        $i=0;//记录多少字段
        echo "<tr>";
        while($row=mysql_fetch_row($ziduan)){
            echo "<td>",$row[0],"</td>";
            $i++;
        }
        echo "<td>操作</td>";
        echo "</tr>";
        while($row=mysql_fetch_row($rs)){
            echo "<tr>";
            for($a=0;$a<$i;$a++){
                echo "<td>",$row[$a],"</td>";
            }
            echo "<td><a href=03.php?id=".$row[0].">编辑</a></td>";
            echo "</tr>";
        }

    ?>
</table>
    
</body>
</html>

 03.php

待定

转载于:https://www.cnblogs.com/lzzhuany/p/4733145.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值