一段很有意思的代码,楼主试一下,应该可以满足你的要求<?php
$conn=mysql_connect("localhost","root","");
$database="mytest"; //表所在数据库
$table ="runtest";//表名称
mysql_select_db($database);
$res=mysql_query("select * from `$table`");
$fields=mysql_list_fields($database,$table);while($r=mysql_fetch_field($fields))
{
echo $r->name." ";
}echo "\n<br>--------------------<br>\n";
while($r=mysql_fetch_array($res,MYSQL_NUM))
{
foreach($r as $v)
{
echo $v." ";
}
echo "\n<br>--------------------<br>\n";
}
?>
$conn=mysql_connect("localhost","root","");
$database="mytest"; //表所在数据库
$table ="runtest";//表名称
mysql_select_db($database);
$res=mysql_query("select * from `$table`");
$fields=mysql_list_fields($database,$table);while($r=mysql_fetch_field($fields))
{
echo $r->name." ";
}echo "\n<br>--------------------<br>\n";
while($r=mysql_fetch_array($res,MYSQL_NUM))
{
foreach($r as $v)
{
echo $v." ";
}
echo "\n<br>--------------------<br>\n";
}
?>
<?php
include "data/mysql_result_all.inc";
$conn = mysql_connect("localhost","root","chizhou");$database = "test"; //数据库名
$table = "test"; //表名$rs = mysql_query("show columns from $table from $database");
mysql_result_all($rs);
?>其中mysql_result_all.inc
<?
/**
* 这是一个非常有用的函数,尤其是在调试时
**/
function mysql_result_all($result,$format="") {
echo "<table $format><tr>";
for($i=0;$i<mysql_num_fields($result);$i++) {
echo "<th>".mysql_field_name($result,$i)."</th>";
}
echo "</tr>";
while($row = mysql_fetch_row($result)) {
echo "</tr>";
for($i=0;$i<mysql_num_fields($result);$i++) {
echo "<td>".$row[$i]."</td>";
}
echo "</tr>";
}
echo "</table>";
}
?>