html/mysql 将查询结果回显到table?
html/mysql echo query results into table?
我正在使用以下 MySQL 查询从我的数据库中获取 select 数据,并将结果回显到 table.
我的问题是第一组结果被正确回显,但是下一行将我的结果显示为垂直向下而不是水平。
这是正在发生的事情:
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>';
} ?>
您在 loop.The 中关闭 table 第一组结果正确回显,因为它仍在第一个循环中,并且会输出您想要的结果,但由于关闭 table,其他结果乱七八糟。 </table>
标记在循环中,但 <table>
不在循环中,因此 </table>
甚至没有关闭任何内容。这意味着您的其余结果实际上并不在 table 中。您需要将 </table>
排除在循环之外。
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>';
还有你上面那个随机 <?php
是怎么回事?
我正在使用以下 MySQL 查询从我的数据库中获取 select 数据,并将结果回显到 table.
我的问题是第一组结果被正确回显,但是下一行将我的结果显示为垂直向下而不是水平。
这是正在发生的事情:
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>';
} ?>
您在 loop.The 中关闭 table 第一组结果正确回显,因为它仍在第一个循环中,并且会输出您想要的结果,但由于关闭 table,其他结果乱七八糟。 </table>
标记在循环中,但 <table>
不在循环中,因此 </table>
甚至没有关闭任何内容。这意味着您的其余结果实际上并不在 table 中。您需要将 </table>
排除在循环之外。
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>';
还有你上面那个随机 <?php
是怎么回事?