我运行多个MySQL查询,并基于变量(例如人员及其功能等)。它应该将数据输出到HTML表中的行和列中。但是,在运行代码时,最终会陷入一团糟,数据没有跟随正确的列。有关更多信息,请参见下图(https://imgur.com/alRkog8)。我似乎无法弄清楚自己在做什么错,因为在我看来我已经正确放置了所有的“ tr”和“ td”。
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>
答案 0 :(得分:1)
至少一个问题可能是从此处嵌套