20210104用PHP程式列出selldb資料庫的custs資料表的所有資料錄(a1.php)

出自金門農工維基館II
跳至導覽 跳至搜尋

0: mysql命令列操作

C:\Users\user>mysql -p -uroot
Enter password: ************
:
mysql> use selldb;
Database changed
mysql> desc custs;
+--------+----------+------+-----+---------+-------+
| Field  | Type     | Null | Key | Default | Extra |
+--------+----------+------+-----+---------+-------+
| id     | char(10) | YES  |     | NULL    |       |
| name   | char(20) | YES  |     | NULL    |       |
| amount | float    | YES  |     | NULL    |       |
| tel    | char(20) | YES  |     | NULL    |       |
+--------+----------+------+-----+---------+-------+
4 rows in set (0.07 sec)

mysql> select * from custs;
+-------+--------+--------+--------+
| id    | name   | amount | tel    |
+-------+--------+--------+--------+
| 10001 | 小狗   |    100 | 233111 |
| 20002 | 小貓   |    200 | 233444 |
| 30003 | 小牛   |    300 | 233777 |
+-------+--------+--------+--------+
3 rows in set (0.00 sec)

mysql> quit
Bye

C:\Users\user>

1: a1.php

<body bgcolor=yellow>
<?php
$con = mysqli_connect('localhost', 'root',
 'abc123abc123', 'selldb');
$sql= "select id,name,amount,tel from custs";
$query     = mysqli_query($con, $sql);
while ($row = mysqli_fetch_array($query)){
        echo  $row['id'] . ":" 
            . $row['name'] . ":" 
            . $row['amount'] . "<br>";
	}
mysqli_close ($con);

?>
</body>

2:result HTML

<body bgcolor=yellow>
10001:小狗:100<br>20002:小貓:200<br>30003:小牛:300<br></body>