(1)c3.php程式碼:
<body bgcolor=green> <?php function exeSQL($con,$sql){ if( $query= mysqli_query($con, $sql) ) {echo " $sql 成功!<br> "; } else { echo " $sql Failure!<br> "; } return $query; }
function dumpTableForDel($table,$con,$bgcolor){ $sql= "select * from $table"; $query=exeSQL($con,$sql); echo "<table bgcolor=$bgcolor border=7>"; echo "<tr bgcolor=cyan>"; $fc= mysqli_num_fields($query) ; while ($field = mysqli_fetch_field($query)){ printf("<td bgcolor=pink>%s", $field->name); } echo "<td>DEL"; $rowc=0; while ($row = mysqli_fetch_array($query)){ echo "<tr bgcolor=purple>"; for ($i=0;$i<$fc;$i++){ echo "<td bgcolor=gray>" . $row[$i]; } echo "<td><a href=c3.php?id=" . $row[0] .">DEL</a>"; $rowc++; } echo "</table>"; echo "total $rowc records <br><br>"; } $con = mysqli_connect('127.0.0.1', 'root', 'w??????', 'selldb'); if (!$con) { echo "Error"; exit(); } $sql = 'set names utf8;'; $query= exeSQL($con,$sql); dumpTableForDel("custs",$con,"yellow"); $id=$_GET['id']; if ($id<>NULL){ $sql="delete from custs where id=$id"; $query= exeSQL($con,$sql); echo "刪掉 id=$id 的資料錄後,custs資料表內容如下<br>"; dumpTableForDel("custs",$con,"cyan"); }
mysqli_close ($con); ?> </body>
(2)執行結果:
set names utf8; 成功! select * from custs 成功!
id |
name |
amount |
tel |
DEL |
10001 |
小狗 |
156 |
08-233375 |
DEL |
10002 |
小貓 |
256 |
08-233375 |
DEL |
10001 |
小草 |
1000 |
08-233375 |
DEL |
10002 |
天牛 |
3000 |
03-933375 |
DEL |
20002 |
天牛 |
3000 |
03-933375 |
DEL |
30002 |
天牛 |
3000 |
03-933375 |
DEL |
total 6 records
delete from custs where id=10001 OK! 刪掉 id=10001 的資料錄後,custs資料表內容如下 select * from custs 成功!
id |
name |
amount |
tel |
DEL |
10002 |
小貓 |
256 |
08-233375 |
DEL |
10002 |
天牛 |
3000 |
03-933375 |
DEL |
20002 |
天牛 |
3000 |
03-933375 |
DEL |
30002 |
天牛 |
3000 |
03-933375 |
DEL |
total 4 records
|