php - MySQL - 如何从 SELECT 查询中获取多个结果
问题描述
此代码仅显示一行。当我执行其中一个查询时,如何显示 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() 的方式有误
推荐阅读
- html - HTML 编辑器中不会出现错误
- python - 如何从数据框中的单个单词组成句子?
- c# - 将字符串替换为 uint
- git - 在错误地提交大文件后,我确实重置为 HEAD^,但我的 .git 文件夹仍然很大。我怎样才能缩小它(删除不需要的包)?
- security - 如何在获取 Oralce JDBC conn 之前将多个 cwallet.sso 文件设置为系统属性
- git - 如果有人提交了未合并的 PR,是否更新本地分支?
- reactjs - 为什么我收到“警告:无法对未安装的组件执行 React 状态更新。这是一个无操作,但它表示内存”的错误
- android-recyclerview - recyclerview中的用户单选按钮如何保存检查状态?
- git - 如何在 github 存储库中按语言获取行数?
- csv - 由于引号,无法在 pyspark 数据框中正确读取 csv 文件