簡體   English   中英

MySQL - 如何從 SELECT 查詢中獲取多個結果

[英]MySQL - how to get multiple results from SELECT query

此代碼僅顯示一行。 當我執行其中一個查詢時,如何顯示 MySQL 表中的其他行? 感謝您提供的任何東西! 幫助表示贊賞!

// Display query results in a table
if ($queryresults) {
    $row = $queryresults->fetch_assoc(); // Problem is here or below
    echo "<table> <tbody><tr><th>Name</th><th>Start Time</th>";
    echo "<th>Duration</th><th>End Time</th>";
    while($row) {
        // Create row of table
        $str = "<tr><td>". $row['name']."</td><td>". $row['starthour'].":";
        $str .= format2($row['startmin'])." ". $row['ampm']."</td><td>". $row['hours'];
        $str .= "h ". format2($row['minutes'])."m</td><td>". $row['endhour'].":";
        $str .= format2($row['endmin'])." ". $row['endampm'] . "</td></tr>";
        echo $str;
        $row = $queryresults->fetch_assoc($queryresults);
    }
    echo "</tbody></table>";
} else {
    echo "Error: #".$connection->errno." – ".$connection->error;
}
// Logout of server
$connection->close();

你能不能試試:

 while ($row = $queryresults->fetch_assoc()) {
 /* do stuff with the $row */
 }

並刪除所有其他$row分配。 我認為您調用 fetch_assoc() 的方式有誤

暫無
暫無

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

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