1 <?php
2 header("Content-Type:text/html;charset=utf-8");
3 function OtherFunction($dbnamem,$tbname){
4 $conn = mysql_connect('localhost','root','') or die(mysql_error());
5 mysql_query("use ".$dbnamem) or die(mysql_error());
6 mysql_query("set names utf8") or die(mysql_error());
7 $sql = "select * from ".$tbname;
8 $res = mysql_query($sql) or die(mysql_error());
9 //取得行数
10 // $rows = mysql_affected_rows($conn);
11 // $rows = mysql_num_rows($res);
12 $colums = mysql_num_fields($res);
13 //取出表头
14 echo "<table border=1><tr>";
15 for ($i=0; $i < $colums; $i++) {
16 # code...
17 $file_name = mysql_field_name($res, $i);
18 echo "<th>$file_name</th>";
19 }
20 echo "</tr>";
21
22 // echo "<tr>";
23 //取出行信息
24 while ($row = mysql_fetch_row($res)) {
25 # code...
26 echo "<tr>"; // 循环输出行
27 for ($i=0; $i < $colums; $i++) {
28 # code...
29 echo "<td>$row[$i]</td>"; //循环输出列
30 }
31 echo "</tr>";
32 }
33 // echo "</tr>";
34
35 echo "</table>";
36
37 }
38 $dbnamem = "mysql";
39 $tbname = "user";
40 OtherFunction($dbnamem,$tbname);
41
42 ?>