The code creates a table in which the currently logged in user details are highlighted in blue. The selection of the currently logged user id done using the session variable $_SESSION['email']
, highlighting is done by giving the tags a CSS class 'curUser'The problem is that the name of a registered user(not the currently logged in user) is displayed in the same row as the currently logged in user. I think the problem is in php/table creation code.
<!DOCTYPE html>
<html>
<head>
</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);
}
} 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>
</html>
Can anyone pinpoint the problem or suggest a solution ?