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

(1)code

<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=a4.php?id=" . $row[0] .">DEL</a>";

        $rowc++;   

}   

echo "</table>";

echo "資料表 $table 共計有 $rowc 筆資料。<br><br>";

}
$con = mysqli_connect('127.0.0.1', 'root', 'w??????', 'selldb');

if (!$con) { echo "Error"; exit(); }

dumpTableForDel("custs",$con,"yellow");
mysqli_close ($con);

?>

</body>

(2)mid result(http://localhost/a4.php)

select * from custs 成功!

id name amount tel DEL
10001 小草8888 1000 08-233375 DEL
10002 天牛 3000 03-933375 DEL
20002 天牛 3000 03-933375 DEL
30002 天牛777 3000 03-933375 DEL

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

(3)final result(http://localhost/a4.php?id=10001)

select * from custs 成功!

id name amount tel DEL
10001 小草8888 1000 08-233375 DEL
10002 天牛 3000 03-933375 DEL
20002 天牛 3000 03-933375 DEL
30002 天牛777 3000 03-933375 DEL

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

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

id name amount tel DEL
10002 天牛 3000 03-933375 DEL
20002 天牛 3000 03-933375 DEL
30002 天牛777 3000 03-933375 DEL

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

 


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