湖濱散記部落格的樹心幽徑[login][主頁]
452:20121221可自selldb資料庫的custs資料表選擇要刪除的資料錄來刪除的PHP程式m4.php

(1) code : m4.php

<body bgcolor=lightblue>
<?php
function DumpTableForDel($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);
    }
    echo "<td>DEL";
    $rowc=0;
    while ($row = mysqli_fetch_array($query)){
        echo "<tr>";
        for ($i=0;$i<$fc;$i++){
            echo  "<td>" . $row[$i];
        }
        echo "<td><a href='m4.php?id=" . $row[0] . "'>DEL</a>";
        $rowc++;
    }
    echo "</table>";
    echo "資料表 $table 共計有 $rowc 筆資料。<br><br>";
}
$con = @mysqli_connect('localhost', 'root', 'w10023', 'selldb');
if (!$con) { echo "Error: " . mysqli_connect_error(); exit(); }
$sql = 'set names utf8;';
if( $query= mysqli_query($con, $sql) ){ echo " $sql OK!<br> "; } else { echo " $sql Failure!<br> "; }
dumpTableForDel("custs",$con,"yellow");
$id=$_GET['id'];
if ($id<>NULL){
    $sql="delete from custs where id=$id";
    if( $query= mysqli_query($con, $sql) ){ echo " $sql OK!<br> "; } else { echo " $sql Failure!<br> "; }
    echo "刪掉 id=$id 的資料錄後,custs資料表內容如下<br>";
    dumpTableForDel("custs",$con,"cyan");
}
mysqli_close ($con);
?>
</body>

(2)執行結果:

set names utf8; OK!
select * from custs OK!

id name amount tel DEL
10001 小草 1000 08-233375 DEL
10002 天牛 3000 03-933375 DEL
10003 地虎 5000 02-444375 DEL

資料表 custs 共計有 3 筆資料。

delete from custs where id=10002 OK!
刪掉 id=10002 的資料錄後,custs資料表內容如下
select * from custs OK!

id name amount tel DEL
10001 小草 1000 08-233375 DEL
10003 地虎 5000 02-444375 DEL

資料表 custs 共計有 2 筆資料。

 


select id,article_id,topic,text from lt_articles_text where article_id =452; ok. update lt_articles set num_reads=num_reads +1 where id=452; ok.