php - mysql 表值合并为一个值而不是多个
问题描述
我的代码遇到了一个问题,这让我很困惑。在下面的代码中,我为要获取的 mysql 数据创建了一个表。但是,当运行我的代码时,所有数据(包括标题、描述和价格)似乎都合并到一个连续的行中,填满了整个页面。我不确定这是否与我试图放入特定行的数据大小有关,或者与我的代码中的错误有关。所以任何帮助将不胜感激。
使用的样式:
table {
border: none;
border-collapse: collapse;
width: 100%;
color: #ffffff;
font-size: 15px;
}
th {
background-color: #a6a6a6;
color: white;
}
table td {
font-size: 5px;
border-left: 1px solid #000;
border-right: 1px solid #000;
}
table td:first-child {
border-left: none;
}
table td:last-child {
border-right: none;
}
</style>
表和 php:
<table>
<tr>
<th>Event Title:</th>
<th>Event Category:</th>
<th>Event Description:</th>
<th>Venue:</th>
<th>Opening Date:</th>
<th>Closing Date:</th>
<th>Price:</th>
</tr>
</table>
<?php //Beginig of php script for database events
include "Database_connection.php"; //Will make the database connection
$sql = "
SELECT e.eventTitle
, c.catDesc
, e.eventDescription
, v.venueName
, e.eventStartDate
, e.eventEndDate
, e.eventPrice
FROM NEE_venue v
JOIN NEE_events e
ON e.venueID = v.venueID
JOIN NEE_category c
ON c.catID = e.catID
ORDER
BY eventTitle ASC
";
$queryResult = $dbConn->query($sql);
if($queryResult === false) { //will detect if the connection failed, and give an error message
echo "<p>Query failed: ".$dbConn->error."</p>\n</body>\n</html>";
exit;
}
else { //if connection is succsessful, code will retrive the events
while($row = $queryResult->fetch_assoc()){
echo "<tr><td>". $row["eventTitle"] ."</td><td>". $row["catDesc"] ."</td><td>". $row["eventDescription"] ."</td><td>". $row["venueName"] ."</td><td>". $row["eventStartDate"] ."</td><td>". $row["eventEndDate"] ."</td><td>". $row["eventPrice"]
."</td></tr>";
}
echo "</table>";
}
$queryResult->close();
$dbConn->close();
?>
问题截图:
解决方案
去掉顶部的结束表标签。
<table>
<tr>
<th>Event Title:</th>
<th>Event Category:</th>
<th>Event Description:</th>
<th>Venue:</th>
<th>Opening Date:</th>
<th>Closing Date:</th>
<th>Price:</th>
</tr>
</table> <--- That one.
从代码和图像看来,数据被打印在表格之外,因为结束表格标签被添加得太早了。
推荐阅读
- node.js - 按时注销用户
- c# - 如何遍历 API Rest 响应中的所有页面
- facebook - 无法从 Facebook API 获取潜在客户信息
- node.js - 人未定义。适用于 msg.guild,但不适用于 client.guilds.cache.get("valid id")
- ios - 更换 ipad 的容器卡在“正在上传 access_control.balance.mx”
- python - 使用正则表达式匹配代码
- python - 为什么 asyncio.sleep(0) 让我的代码更快?
- node.js - 试图循环遍历一个数组。在显示它们时遇到问题
- python - 提交评论后重定向到帖子
- ios - 如何从 Firebase 数据库中的 autoID 获取价值 - Swift