简体   繁体   English

将mysql返回的多行打印到php

[英]Print multiple rows returned by mysql to php

I want to make a php web page which will query the mysql db and mysql might return more than 1 row.我想制作一个 php 网页,它将查询 mysql db,而 mysql 可能会返回超过 1 行。 I want to print those rows one after another.我想一个接一个地打印这些行。

        $query = "SELECT * FROM tables WHERE name = 'table1';";
        $req = mysqli_query($conn, $query);
        $res = mysqli_fetch_assoc($req);

I want to print something like this我想打印这样的东西

 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

Please note that php array keys are case sensitive.请注意,php 数组键区分大小写。 So there's a difference between所以有区别

$res["Poem_id"]

and

$res["poem_id"]

Also don't forget to use htmlentities().也不要忘记使用 htmlentities()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM