码迷,mamicode.com
首页 > 数据库 > 详细

页面化操作数据库

时间:2015-08-15 22:47:08      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

首先默认选择库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

待定

页面化操作数据库

标签:

原文地址:http://www.cnblogs.com/lzzhuany/p/4733145.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!