【发布时间】:2015-04-20 12:37:05
【问题描述】:
我正在使用以下 MySQL 查询从我的数据库中选择数据并将结果回显到表中。
我的问题是第一组结果被正确回显,但是下一行显示我的结果垂直向下而不是水平。
这是发生了什么:
Heading1 Heading2 Heading3 Heading4 Heading5
a b c d e
a
b
c
d
e
请有人告诉我哪里出错了。这是我的代码:
<?php
$conn = new mysqli($host, $username, $password, $db_name);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error); }
$sql = "select * from new_supplier_request where status!= 'complete' and action_taken ='actioned'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo '<table><tr><td><p><u>Request By</u></p></td><td><p><u>Date</u></p></td><td><p><u>Status</u></p></td><td><p><u>Supplier Name</u></p></td><td><p><u>Action</u></p></td></tr>';
while($row = $result->fetch_assoc()) {
$datetime = strtotime($row['date']);
$mysqldate = date("D, d M Y ", $datetime);
echo '<tr>';
echo '<td><p>'.$row['user_id'].'</p></td>';
echo '<td><p>'.$row['user_id'].'</p></td>';
echo '<td><p>'.$row['user_id'].'</p></td>';
echo '<td><p>'.$row['user_id'].'</p></td>';
echo '<td><p><a href="process/action.php?reference='.$row['reference'].'" id="action">Action</a> / <a href="process/decline.php?reference='.$row['reference'].'" id="decline">Decline</a></p></td></tr>';
}
echo '</table>';
}else{
echo'<div class="no_requests">No New Supplier Request's</div>';
} ?>
【问题讨论】:
-
为什么每次循环迭代都关闭表
</table>?你应该在事后关闭它 -
你在 while 循环中关闭了
</table>.. 把它放在外面
标签: php mysql html-table