簡體   English   中英

PHP的while循環不顯示結果

[英]php while loop not showing results

有人可以指出我確定代碼中有一個非常明顯的錯誤嗎? 我的while循環中的字符串“ string”顯示正確的時間,但不顯示row [0]中的結果。

if (!isset($_GET['city']) & !isset($_GET['county'])) {
    $getResults = "SELECT DISTINCT region FROM `locations` WHERE country = 'England'";
    echo "No region or county set";

    if ($result = $mysqli->query($getResults)) {
        echo "Found results";

        while ($row = $result->fetch_assoc()) {
            echo "string";
            echo $row[0];
        }
    }
}

要查看$ row數組的內容,請像var_dump($row)一樣將其轉儲出去。

我猜你只需要echo $row['region']而不是$row[0]

您正在使用fetch_assoc()但嘗試使用索引號訪問該行。

請改用fetch_row()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM