gpt4 book ai didi

php - HTML 表无法正确显示 MySQL 数据

转载 作者:行者123 更新时间:2023-11-29 09:50:03 24 4
gpt4 key购买 nike

我运行多个 MySQL 查询,并基于诸如人员、功能等变量。它应该将数据输出到 HTML 表中的行和列中。然而,当代码运行时,它最终会陷入一团困惑,数据没有遵循正确的列。有关详细信息,请参阅下图 ( https://imgur.com/alRkog8 )。我似乎无法弄清楚我做错了什么,因为在我看来,我已经正确放置了所有“tr”和“td”。 This is how the HTML table ends up looking on the webpage

    session_start();
if(!isset($_SESSION['user1'])){
header("location:".WEBROOT."index.php");
exit();
}
include_once DOCROOT . 'DBconnect.php';
?>

<html>
<head>
<?php
$title = "Participants";
$file = __FILE__;
include DOCROOT . 'pages/menu.php';
?>
<div id="content">
<div class="widecontentitem" id="lastitem">
<?php
$result = mysqli_query($db_link, 'SELECT institutionID FROM users WHERE users.UserID = \'' . $_SESSION['user1'] . '\'');
if (!$result) {
die('Invalid query: ' . mysqli_error());
}
$institutionID = "";
while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
$institutionID = $row[0];
}
print "<input type=\"hidden\" id=\"institution\" value=\"" . $institutionID . "\"> ";
$result = mysqli_query($db_link, 'SELECT participants.name, participants.surname, participants.email, participants.special, participants.housingcomments, participants.functionID, participants.infix, participants.committee, participants.dateOfBirth, participants.housing, participants.countryID, participants.participantID FROM participants WHERE participants.institutionID =' . $institutionID);
if (!$result) {
die('Invalid query:2 ' . mysqli_error());
}
print "<table>";
print "<tr><th><b>Function</b></th><th><b>Name</b></th><th><b>Surname</b></th><th><b>Date Of Birth</b></th><th><b>Country</b></th><th><b>Committee</b></th></tr>";
while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
if($row[9]==1){
$row[0] = "(H)" . $row[0];
}

if( $row[5]==4){
$title = "Delegate ";
$result3 = mysqli_query($db_link, 'SELECT delegation FROM delegations WHERE ambassadorID =' . $row[11] );
$num_rows = mysqli_num_rows($result3);
if($num_rows==1){
$title = "Ambassador ";
}
$result2 = mysqli_query($db_link, 'SELECT delegation FROM delegations WHERE delegationID = ' . $row[10] );
while ($row2 = mysqli_fetch_array($result2, MYSQLI_NUM)) {
print "<tr><td>$title </td><td>$row[0] </td><td>$row[1] </td><td>$row[8] </td><td>$row2[0] </td><td>$row[7] </td></tr>";
}
}
if( $row[5]==2){
print "<tr><td>MUN-Director </td><td>$row[0] </td><td>$row[1] </td><td>$row[8] </td><td></td><td></td></tr>";
}
if($row[5]==5){
print "<tr><td>President </td><td>$row[0] </td><td>$row[1] </td><td>$row[8] </td><td></td><td>$row[7] </td></tr>";
}
if($row[5]==6){
print "<tr><td>Deputy President </td><td>$row[0] </td><td>$row[1] </td><td>$row[8] </td><td></td><td>$row[7] </td></tr>";
}
if($row[5]==7){
print "<tr><td>Chair </td><td>$row[0] </td><td>$row[1] </td><td>$row[8] </td><td></td><td>$row[7] </td></tr>";
}
if($row[5]==8){
print "<tr><td>Deputy Chair </td><td>$row[0] </td><td>$row[1] </td><td>$row[8] </td><td></td><td>$row[7] </td></tr>";
}
if($row[4]!=NULL || $row[3]!=NULL){
print "<table>";
if($row[3]!=NULL){
print "<tr><td colspan=\"6\">Comments: </td><td>$row[3] </td></tr>";
}
if($row[4]!=NULL){
print "<tr><td colspan=\"6\">Housing: </td><td>$row[4] </td></tr>";
}
print "</table>";
}
}
print "</table>";
?>
</div>
<?php include '../footer.php';?>
</div>
</body>
</html>

最佳答案

至少有一个问题可能是这里嵌套的

if($row[4]!=NULL || $row[3]!=NULL){
print "<table>";
if($row[3]!=NULL){

来自MDN Table Element Doc :

Permitted content In this order:

  • an optional <caption> element,
  • zero or more <colgroup> elements,
  • an optional <thead> element,
  • either one of the following:
    • zero or more <tbody> elements
    • one or more <tr> elements
  • an optional <tfoot> element

您可能想要使用类似 Nu Html 的内容来验证 HTML。使用它的一种方法是

  • 右键单击页面并选择“查看页面源代码”或类似选项,具体取决于您的浏览器
  • 全选并复制
  • 选择检查方式:text input在验证器中
  • 粘贴页面源代码,然后单击“检查”

关于php - HTML 表无法正确显示 MySQL 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54968767/

元素:

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com