//在表格中显示表的数据,常用方式
function ShowTable($table_name){
$conn=mysql_connect("localhost","root","toor");
if(!$conn){
echo "连接失败";
}
mysql_select_db("test",$conn);
mysql_query("set names utf8");
$sql="select * from $table_name";
$res=mysql_query($sql,$conn);
$rows=mysql_affected_rows($conn);//获取行数
$colums=mysql_num_fields($res);//获取列数
echo "test数据库的"."$table_name"."表的所有用户数据如下:
";
echo "共计".$rows."行 ".$colums."列
";
echo "";
for($i=0; $i < $colums; $i++){
$field_name=mysql_field_name($res,$i);
echo "$field_name";
}
echo "";
while($row=mysql_fetch_row($res)){
echo "
";
for($i=0; $i
echo "$row[$i]";
}
echo "";
}
echo "";
}
ShowTable("test1");