简体   繁体   English

MySQL - 如何从 SELECT 查询中获取多个结果

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

This code is only displaying one row.此代码仅显示一行。 How can I show the other rows that are in the MySQL table when I execute one of the queries?当我执行其中一个查询时,如何显示 MySQL 表中的其他行? Thank you for anything you can offer!感谢您提供的任何东西! Help is appreciated!帮助表示赞赏!

// 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();

Could you try:你能不能试试:

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

And remove every other $row assignment.并删除所有其他$row分配。 I think there is a mistake in the way you are calling fetch_assoc()我认为您调用 fetch_assoc() 的方式有误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM