mysql-如何从select查询中获得多个结果

fv2wmkja  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(338)

此代码仅显示一行。在执行其中一个查询时,如何显示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();
oewdyzsn

oewdyzsn1#

你能试试吗:

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

把其他的都去掉 $row 转让。我认为你叫fetch\u assoc()的方式有误

相关问题