代码创建了一个表,其中当前登录的用户详细信息以蓝色突出显示。这是通过使用$_SESSION['email']
来标识当前登录的用户来完成的。
在表构造中,元素被声明为css类curUser
。这个.curUser
在CSS文件中用于识别和颜色/突出显示当前登录的用户。
问题是在选择当前用户之后创建了一个空白行/行。我很确定问题是php表创建代码。
有没有人能帮我看一下,并指出问题所在,因为我现在不明白。
HTML:</head>
<body>
<h1>Selections</h1>
<?php
require 'configuration.php';
require 'connectTodb.php';
?>
<table border="1" id="parent" >
<tr>
<th>#</th>
<th>Name</th>
<?php
for ($i = 1; $i < 6; $i++) {
print("<th>Week " . $i . "</th>");
}
?>
</tr>
<?php
$sql = "SELECT selections.week,selections.team,users.email,users.name,selections.outcome FROM users,selections WHERE users.email = selections.email ORDER BY name,week";
$result = mysqli_query($connection, $sql);
print mysql_error();
if (!$result) {
die('Could not query:' . mysql_error());
}
$rowId = 0;
$rows = mysqli_fetch_assoc($result);
while ($rows != null) {
print("<tr>");
$rowId++;
$name = $rows["name"];
if ($rows['email'] == $_SESSION['email']) {
print("<td class=" . $curUser . " type='hidden' value=" . $rows['email'] . ">" . $rowId . "</td>");
print("<td class=" . $curUser . "> " . $rows["name"] . "</td>");
while ($rows != null & $name == $rows['name']) {
print("<td class=" . $curUser . "> " . $rows["team"] . "</td>");
$rows = mysqli_fetch_assoc($result);
}
print("</tr>");
} else {
print("<td type='hidden' value=" . $rows['email'] . ">" . $rowId . "</td>");
}
print("<td> " . $rows["name"] . "</td>");
while ($rows != null & $name == $rows['name']) {
print("<td > " . $rows["team"] . "</td>");
$rows = mysqli_fetch_assoc($result);
}
print("</tr>");
}
?>
</table>
<?php
mysqli_close($connection);
?>
</body>
CSS .curUser, #rowId {
background-color: lightblue;
}
您关闭了两次表行:
while ($rows != null & $name == $rows['name']) {
print("<td class=" . $curUser . "> " . $rows["team"] . "</td>");
$rows = mysqli_fetch_assoc($result);
}
print("</tr>");
:
while ($rows != null & $name == $rows['name']) {
print("<td > " . $rows["team"] . "</td>");
$rows = mysqli_fetch_assoc($result);
}
print("</tr>");