簡體   English   中英

循環通過mysqli的結果

[英]Looping through results in mysqli

我是mysqli的新手,並且遇到了使用mysqli循環結果的問題。 不幸的是,我只得到了一個結果。 當我將查詢放入phpMyAdmin時,它會得到三個結果。 我相信相關的代碼在這里,我只是稱錯了:

$connection = new mysqli($host, $databaseUsername, $databasePassword, $database);

if ($connection->connect_errno > 0) {
    die ('Unable to connect to database [' . $connection->connect_error . ']');
}

$sql = "SELECT clientId, studentFirstName, studentLastName
        FROM clients
        WHERE (studentEmail = '$postEmail') OR (parentEmail = '$postEmail');";  

if (!$result = $connection->query($sql)) {
    die ('There was an error running query[' . $connection->error . ']');
}

echo '<select class = "toolbarDropdown" id = "toolbarDropdown-MultipleAccounts">';

    while ($row = $result->fetch_array()) {
        echo '<option value="'.$row["clientId"].'">'.$row["studentFirstName"].' '.$row["studentLastName"].'</option>';
    }

echo '</select>';

您在HTML中缺少結束“at option =”值< -

注意

$row = $result->fetch_array()

可以替換為

$row = $result->fetch_assoc()

這樣做,您獲取的每個記錄的數組將占用一半的大小。

暫無
暫無

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

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