效果图1
<form id="form1" name="form1" action="2.php" method="get">
本数据库中有以下表:<input type="text" name="shuru" value=""/>
<input type="submit" name="sub" value="查询">
</form> <?php
/**
* By: Qingsong
* Date: 2015/4/18 0018
* Time: 22:17
*/
header('content-type:text/html;charset=utf-8');
$jieshou ="qingsong";
define("connect",@mysql_connect("localhost","root","root")); //列出表名
//echo "数据库--".$jieshou."<br/><br/>";
$dbs = @mysql_list_tables("qingsong",connect);
$rows = mysql_num_rows($dbs);
$i = 0;
while($i <$rows)
{
$db_name[$i] = mysql_tablename($dbs , $i);
echo $db_name[$i]."</br>" ;
$i++;
}
效果图2
<?php
/**
* By: Qingsong
* Date: 2015/4/21 0021
* Time: 21:52
*/
header('content-type:text/html;charset=utf-8');
@$conn=new mysqli("localhost","root","root");
if($conn->connect_error) die("数据库连接失败".$conn->connect_error);
$shuru=$_GET["shuru"];
function chaxun($shuru){
@$conn=new mysqli("localhost","root","root");
$conn->select_db("qingsong"); $sql="SHOW FULL COLUMNS FROM "."$shuru";
$result=$conn->query($sql);
if(!$result) die("数据查询失败"); //$row_num=$result->num_rows;
//$col_num=$result->field_count;
//echo" 行数为:$row_num,列数为:$col_num ";
echo "<br/>"; echo "<table bordercolor=#4F88EF align=center border=1><tr>";//表格
while ($field=$result->fetch_field())
{
echo "<th>$field->name</th>";//$field的name属性..
}
echo "</tr>"; while($res=$result->fetch_row())
{
echo "<tr>";
foreach($res as $val)
echo "<th>$val</th>";
echo "</tr>";
}
echo "</table>";
} chaxun($shuru);
?> <input type="button" onclick="window.location.href='4.php'" value="查看数据">
<?php
/**
* By: Qingsong
* Date: 2015/4/21 0021
* Time: 22:39
*/
header('content-type:text/html;charset=utf-8');
$link=mysql_connect("localhost","root","root");
if(!$link) echo "数据库没有连接成功!";
else echo "数据库连接成功!<br/>";
mysql_select_db("qingsong", $link); //选择数据库
$q = "SELECT * FROM admin"; //SQL查询语句
mysql_query("SET NAMES utf8");
$rs = mysql_query($q, $link); //获取数据集
if(!$rs){die("Valid result!");}
echo "<table>";
echo "<tr><td>ID</td><td>管理账号</td><td>性别</td><td> 密码</td><td>注册日期</td><td>前台马甲</td></tr>";
while($row = mysql_fetch_row($rs)) echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td><td>$row[5]</td></tr>"; //显示数据
echo "</table>";
mysql_free_result($rs); //关闭数据集
echo "<br/><br/> <a href=3.php?id=qingsong>返回</a>"." <br>";