0

我正在尝试使用 PHP 遍历 MySQL 表,但它只显示一行。

            //Retrieve a list of outstanding developments
            $sql = "SELECT * FROM tblDevelopment WHERE strStatus=?";
            $statement = mysqli_stmt_init($conn);

            //Check for any errors in the SQL statement
            if (!mysqli_stmt_prepare($statement,$sql)){

                //Report any errors with the prepared $statement
                header("Location: ../sqlerror.php");
                exit();

            } else {

                //If there are no errors, query the database for the username
                mysqli_stmt_bind_param($statement,'s', $status);
                mysqli_stmt_execute($statement);
                $results = mysqli_stmt_get_result($statement);

                if ($row = mysqli_fetch_assoc($results)) {

                    echo 'header';

                    while ($row = mysqli_fetch_assoc($results))
                    {
                         echo $row['strDetail'] . "</";
                    }

                    echo 'footer';

                } else {

                    echo 'No results to display';

                }

            }

该代码在没有结果时有效,但是当有多个结果时它只显示一个结果 - 知道我做错了什么吗?

4

1 回答 1

0

您快到了……您需要继续调用mysqli_fetch_assoc,直到到达结果集的末尾。将您的更改if为 awhile应该足以让您滚动。

while (($row = mysqli_fetch_assoc($results)) !== null) {

于 2019-09-12T23:17:51.237 回答