问题描述:

The code creates a table in which the currently logged in user details are highlighted in blue. This is done using a $_SESSION['email'] to identify the currently logged in user.

Within the table construction the elements are declared as a css class curUser. This .curUser is used in the CSS file to identify and colour/ highlight the current logged in user.

The problem is that a blank line/row is created after the current user has been selected. I am fairly sure that the problem is the php table creation code.

Can someone please have a look at this and point out the problem, as it is eluding me at present?

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;

}

网友答案:

You are closing the table row twice:

                while ($rows != null & $name == $rows['name']) {
                    print("<td class=" . $curUser . "> " . $rows["team"] . "</td>");
                    $rows = mysqli_fetch_assoc($result);
                }
                print("</tr>");

and here:

            while ($rows != null & $name == $rows['name']) {
                print("<td > " . $rows["team"] . "</td>");
                $rows = mysqli_fetch_assoc($result);
            }
            print("</tr>");
相关阅读:
Top