[英]Print multiple rows returned by mysql to php
我想制作一個 php 網頁,它將查詢 mysql db,而 mysql 可能會返回超過 1 行。 我想一個接一個地打印這些行。
$query = "SELECT * FROM tables WHERE name = 'table1';";
$req = mysqli_query($conn, $query);
$res = mysqli_fetch_assoc($req);
我想打印這樣的東西
Poem_id | Poem_content | Poem_by | Poem_hotscore
------------ ----------------- ----------- -----------------
1 | Blah Bleh<br>B.| 4 | 5342.3920349
7 | Blah Bluu<br>F.| 4 | 5003.3920382
9 | Blerp Bloop Foo| 34 | 4300.7281209
while (($res = mysqli_fetch_assoc($req)) !== NULL)
echo $res["Poem_id"]." | ".$res["Poem_content"]."<br />"; // and so on
請注意,php 數組鍵區分大小寫。 所以有區別
$res["Poem_id"]
和
$res["poem_id"]
也不要忘記使用 htmlentities()。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.