PHP读取表字段并导出数据表
<?php
require 'config.php';
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>导出数据库表模板</title>
<style>
table{
border-right:1px dashed #e8e6e6;
border-bottom:1px dashed #e8e6e6;
}
table td{
border-left:1px dashed #e8e6e6;
border-top:1px dashed #e8e6e6;
line-height:20px;
font-size:12px;
text-align:right;
padding-right:5px;
white-space: nowrap;
}
</style>
</head>
<body><table cellspacing="0" cellpadding="0" >
<tr style="background:#eeeded;">
<td>序号</td>
<?php
$query = mysql_query("SHOW FULL COLUMNS FROM rs_person") or die('SQL 错误!');
//echo mysql_affected_rows()." 个字段<br>";
$fieldnum = 0;
while (!!$row = mysql_fetch_array($query, MYSQL_ASSOC)) {
//$json .= $row[Field].'-'.$row[Comment].'<br>';
$fieldsrr[$fieldnum]=$row[Field]; //数组存储字段名
echo "<td>$row[Comment]</td>";
$fieldnum++;
}
?>
</tr>
<?php
$sql = "SELECT * FROM rs_person";
$myrun = mysql_query($sql) or die('SQL 错误!');
$num=0;
while($myrow=mysql_fetch_array($myrun)){
$num++;
echo "<tr>";
echo "<td>$num</td>";for($i=0;$i<count($fieldsrr);$i++){
$fieldname = $fieldsrr[$i];
echo "<td>$myrow[$fieldname]</td>";
}
echo "</tr>";
}
mysql_close();
?>
</table></body>
</html>
转载请注明:RAIN MAN » PHP读取表字段并导出数据表
还没有人抢沙发呢~