湖濱散記部落格的樹心幽徑[login][主頁]
455:20181224設計PHP函數dumpTable來列出selldb資料庫的custs資料表的全部資料錄(a3.php)

(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 筆資料。

 


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