<table>
    <thead>
        <tr>
            <th></th>
            <th>MENU A</th>
            <th>MENU B</th>
            <th>MENU C</th>
            <th>MENU D</th>
            <th>MENU E</th>
            <th>UKUPNO</th>
        </tr>
    </thead>
    <tbody>
        <?php
        $i = 0;
        for ($i=0; $i<$number_users; $i++) {
        ?>
            <tr>
                <td><?php echo $all_users[$i] ?></td>
                <?php
                    $countA = 0;
                    $countB = 0;
                    $countC = 0;
                    $countD = 0;
                    $countE = 0;
                    $sum = 0;
                    $query = "SELECT * FROM orders WHERE YEAR(date) = YEAR(CURRENT_DATE()) AND MONTH(date) = $month_this AND completed = '1' AND user = '$all_users[$i]'";
                    $result = mysqli_query($dbc, $query);
                    while($row = mysqli_fetch_array($result)) {
                        if ($row['user'] == $all_users[$i] && $row['menu'] == 'A') {
                            $countA += 1;
                        } else if ($row['user'] == $all_users[$i] && $row['menu'] == 'B') {
                            $countB += 1;
                        } else if ($row['user'] == $all_users[$i] && $row['menu'] == 'C') {
                            $countC += 1;
                        } else if ($row['user'] == $all_users[$i] && $row['menu'] == 'D') {
                            $countD += 1;
                        } else if ($row['user'] == $all_users[$i] && $row['menu'] == 'E') {
                            $countE += 1;
                        } 
                    }
                    $sum = $countA + $countB + $countC + $countD + $countE;
                    echo "<td>".$countA."</td>";
                    echo "<td>".$countB."</td>";
                    echo "<td>".$countC."</td>";
                    echo "<td>".$countD."</td>";
                    echo "<td>".$countE."</td>";
                    echo "<td>".$sum."</td>";
                ?>
            </tr>
        <?php
        }
        ?>
        <tr>
            <td colspan="6" style="text-align:right;"><b>UKUPNO</b></td>
            <?php
                $month_sum = 0;
                $query = "SELECT * FROM orders WHERE YEAR(date) = YEAR(CURRENT_DATE()) AND MONTH(date) = $month_this AND completed = '1'";
                $result = mysqli_query($dbc, $query);
                while($row = mysqli_fetch_array($result)) {
                    $month_sum += 1;
                }
                echo "<td><b>".$month_sum."</b></td>";
            ?>
        </tr>
    </tbody>
</table>