我正在使用以下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>
标签是在循环,但<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
您上方的随机事件是怎么回事?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句