代码创建一个表,其中当前登录的用户详细信息以蓝色突出显示。这是使用$_SESSION['email']
来识别当前登录的用户。
在表构造中,元素被声明为css类curUser
。 CSS文件中使用此.curUser
来标识和突出显示当前登录的用户。
问题是在选择当前用户后会创建一个空白行/行。我很确定问题是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;
}
答案 0 :(得分:0)
您正在关闭表格行两次:
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>");