<?php
include "../backend/connection.php";
$configure = new DefaultDatabase();
$conf = $configure->connect();

$tables = mysqli_query($conf,"SELECT * FROM categories");

?>
<div class="school-container">
    <h2>PARTICIPANTS RESULTS PERFORMANCE</h2>
    <br>
    <?php
        while($data = mysqli_fetch_array($tables))
        {
            //sort to sections
             echo  "<h3 style='font-'>". $data["category_name"] ."</h3>";
            $sections = mysqli_query($conf,"SELECT * FROM grade_section");
            while($sec = mysqli_fetch_array($sections))
            {
    ?>
    <h4><i><?php echo $sec["section_name"] ?></i></h4>
    <table>
        <thead>
            <tr>
                <th>Participant Name</th>
                <th>Level</th>
                <th>District</th>
                <th>School</th>
                <th>Category</th>
                <th>Points</th>
                <th>Position</th>
            </tr>
        </thead>
        <tbody>
            <?php
            // Check results specific
                $pos = 0;
                $result = mysqli_query($conf, "SELECT * FROM participants WHERE category = '".$data["category_name"]."' AND grade_section = '".$sec["section_name"]."' ORDER BY points DESC");
                while ($res = mysqli_fetch_array($result)) {
            ?>
            <tr>
                <td><?php echo $res["first_name"]." ".$res["last_name"]; ?></td>
                <td><?php echo ($res["grade_section"]); ?></td>
                <td><?php echo ($res["district"]); ?></td>
                <td><?php echo ($res["school"]); ?></td>
                <td><?php echo ($res["category"]); ?></td>
                <td><?php echo ($res["points"]); ?></td>
                <td><?php echo ($pos+1); ?></td>
            </tr>
            <?php 
                    $pos++;
                    }
            ?>
        </tbody>
    </table>
    <?php
            }
            echo "<hr>";
        }
    ?>
</div>