0

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 ?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Tony75
  • 47
  • 2
  • I think the real problem is in the HTML logic rather than php. Just needs to end the row before entering the registered user details – Arjun Aug 29 '16 at 17:04
  • Why do you close off the else block right after that first print statement? Maybe try moving the second print and while loop into the else block. – fuandon Aug 29 '16 at 17:09
  • @RiggsFolly Why is this a duplicate? The questions are nothing alike. – fuandon Aug 29 '16 at 17:16
  • You have used `mysql_error()` twice So your code must be generating an error to the php error log even if you have turned erro displays to the screen off – RiggsFolly Aug 29 '16 at 17:16

0 Answers0