(1) code
<body background=dog.png> <?phpfunction dumpTable($table,$con,$bgcolor){ $sql= "select * from $table"; if( $query= mysqli_query($con, $sql) ){ echo " $sql OK!<br> "; } else { echo " $sql Failure!<br> "; } echo "<table bgcolor=$bgcolor border=3>"; echo "<tr>"; $fc= mysqli_num_fields($query) ; while ($field = mysqli_fetch_field($query)){ printf("<td>%s", $field->name); } $rowc=0; while ($row = mysqli_fetch_array($query)){ echo "<tr>"; for ($i=0;$i<$fc;$i++){ echo "<td>" . $row[$i]; } $rowc++; } echo "</table>"; echo "資料表 $table 共計有 $rowc 筆資料。<br><br>";} $con = mysqli_connect('127.0.0.1', 'root', 'w1xxxx???', 'selldb');if (!$con) { echo "Error"; exit(); }dumpTable("custs",$con,"red");dumpTable("custs",$con,"pink");dumpTable("custs",$con,"purple"); mysqli_close ($con);?></body>
(2)result
select * from custs OK!
id |
name |
amount |
tel |
10001 |
小草 |
1000 |
08-233375 |
10002 |
天牛 |
3000 |
03-933375 |
20002 |
天牛 |
3000 |
03-933375 |
30002 |
天牛 |
3000 |
03-933375 |
資料表 custs 共計有 4 筆資料。
select * from custs OK!
id |
name |
amount |
tel |
10001 |
小草 |
1000 |
08-233375 |
10002 |
天牛 |
3000 |
03-933375 |
20002 |
天牛 |
3000 |
03-933375 |
30002 |
天牛 |
3000 |
03-933375 |
資料表 custs 共計有 4 筆資料。
select * from custs OK!
id |
name |
amount |
tel |
10001 |
小草 |
1000 |
08-233375 |
10002 |
天牛 |
3000 |
03-933375 |
20002 |
天牛 |
3000 |
03-933375 |
30002 |
天牛 |
3000 |
03-933375 |
資料表 custs 共計有 4 筆資料。
|