PHP& mySQLi - 而mysqli_fetch_array没有回显结果

时间:2013-05-17 03:17:32

标签: php mysqli while-loop echo fetch

尝试回显行。我没有得到任何错误,但如果我做第二部分它就有效。

<?php

$result = mysqli_query($db_connect, "SELECT * FROM items") or die ("Query is invalid." . mysqli_error());

if (!$row = mysqli_fetch_array($result)) {
    echo "</table>".
        "<font color='red'>".
        "There are no items in the databse.".
        "</font>";
} else {
    while ($row = mysqli_fetch_array($result)) {

        echo $row['Item_SKU'];
    }
}

?>

这将打印数据库中的第一个项目,而不是所有项目

<?php

    $result = mysqli_query($db_connect, "SELECT * FROM items") or die ("Query is invalid." . mysqli_error());

    if (!$row = mysqli_fetch_array($result)) {
        echo "</table>".
            "<font color='red'>".
            "There are no items in the databse.".
            "</font>";
    } else {
                echo $row['Item_SKU'];
        //while ($row = mysqli_fetch_array($result)) {
        //
        //  echo $row['Item_SKU'];
        //}
    }

?>

0 个答案:

没有答案