使用 PHP 返回行的问题

发布于 2024-08-13 16:58:44 字数 1869 浏览 7 评论 0原文

<?php

if (isset($_GET['flyerID']))
    $FlyerID = $_GET['flyerID'];

$DBConnect = @mysqli_connect("host", "UN", "pword")

    Or die("<p>Unable to connect to the datbase server.</p>" . "<p>Error Code ".mysqli_connect_errno().": ".mysqli_connect_error()) . "</p>";

$DBName = "agentsleuthdb";

@mysqli_select_db($DBConnect, $DBName)

    Or die("<p>Unable to select the database.</p>" . "<p>Error Code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) ."</p>";

    $TableName = "FEEDBACK";

    $SQLstring = "SELECT * FROM $TableName order by FIRSTNAME";

    $QueryResult = @mysqli_query ($DBConnect, $SQLstring)

    Or die("<p> Unable to exequte Select query.</p>"."<p>Error Code ".mysqli_errno($DBConnect) .": ".mysqli_error

($DBConnect))."</p>";

    if (mysqli_num_rows($QueryResult) == 0){

        exit("<p>There is no feedback</p>");
}

?>


            <table border="1">
                <tr>
                    <th width = "15%">First Name </th>
                    <th width = "15%">Last Name </th>
                    <th width = "15%">Email Addr </th>
                    <th width = "15%">Company </th>
                    <th width = "40%">Feedback </th>

                </tr>


<?php
    $Row = mysqli_fetch_row($QueryResult);

do {
    echo "<tr><td>{$Row[0]}</td>";
    echo "<td>{$Row[1]}</td>";
    echo "<td>{$Row[2]}</td>";
    echo "<td>{$Row[3]}</td>";
    echo "<td>{$Row[4]}</td></tr>";
    $Row = mysqli_fetch_assoc($QueryResult);
} while ($Row);
mysqli_free_result($QueryResult);
mysqli_close($DBConnect);
?>              

它只返回一行..我怎样才能返回所有条目?

<?php

if (isset($_GET['flyerID']))
    $FlyerID = $_GET['flyerID'];

$DBConnect = @mysqli_connect("host", "UN", "pword")

    Or die("<p>Unable to connect to the datbase server.</p>" . "<p>Error Code ".mysqli_connect_errno().": ".mysqli_connect_error()) . "</p>";

$DBName = "agentsleuthdb";

@mysqli_select_db($DBConnect, $DBName)

    Or die("<p>Unable to select the database.</p>" . "<p>Error Code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) ."</p>";

    $TableName = "FEEDBACK";

    $SQLstring = "SELECT * FROM $TableName order by FIRSTNAME";

    $QueryResult = @mysqli_query ($DBConnect, $SQLstring)

    Or die("<p> Unable to exequte Select query.</p>"."<p>Error Code ".mysqli_errno($DBConnect) .": ".mysqli_error

($DBConnect))."</p>";

    if (mysqli_num_rows($QueryResult) == 0){

        exit("<p>There is no feedback</p>");
}

?>


            <table border="1">
                <tr>
                    <th width = "15%">First Name </th>
                    <th width = "15%">Last Name </th>
                    <th width = "15%">Email Addr </th>
                    <th width = "15%">Company </th>
                    <th width = "40%">Feedback </th>

                </tr>


<?php
    $Row = mysqli_fetch_row($QueryResult);

do {
    echo "<tr><td>{$Row[0]}</td>";
    echo "<td>{$Row[1]}</td>";
    echo "<td>{$Row[2]}</td>";
    echo "<td>{$Row[3]}</td>";
    echo "<td>{$Row[4]}</td></tr>";
    $Row = mysqli_fetch_assoc($QueryResult);
} while ($Row);
mysqli_free_result($QueryResult);
mysqli_close($DBConnect);
?>              

It only returns one row.. how can I return all entries?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只有影子陪我不离不弃 2024-08-20 16:58:45

您是否尝试过

while ($Row = mysqli_fetch_row($QueryResult))

描述此处

while ($Row = mysqli_fetch_array($QueryResult, MYSQL_ASSOC))

描述这里

希望这会有所帮助。

Have you tried

while ($Row = mysqli_fetch_row($QueryResult))

Description here

or

while ($Row = mysqli_fetch_array($QueryResult, MYSQL_ASSOC))

Description here

Hope this helps.

关于从前 2024-08-20 16:58:45

在您的代码中,仅在您第一次调用 mysqli_fetch_row 时,这会使 $Row 成为索引数组。
这就是为什么当您使用索引访问 $Row 的内容时会看到输出 ($Row[0], $Row[1] , ETC..)。
之后,您mysqli_fetch_assoc$Row转换为关联数组,因此使用输出索引访问$Row不再起作用。

将您的 do ... while 循环替换为 forloney 建议的第一个 while 循环。

In your code, only the first time you call mysqli_fetch_row, which makes an $Row an indexed array.
This is why you see output when you access the content of $Row with an index ($Row[0], $Row[1], etc..).
Afterwards, you mysqli_fetch_assoc which turns $Row in an associative array, thus accessing $Row with an index for your output doesn't work anymore.

Replace your do ... while loop by the first while loop aforloney suggested.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文