0

I'm trying to build a table for my NCAA bracket and I am having issues getting the calculations to work. Essentially, I'm trying to achieve the following process:

  1. Does Gary's choice (Column 4) equal the Result (Column 2)?
  2. If so, add the points for that game (Column 3) to variable $total.
  3. Repeat for each row (representing game), so at the end $total equals total points.

    +-------+--------+--------+-------+-------+
    | Game  | Result | Points | 101   | 102   |
    +-------+--------+--------+-------+-------+
    | game1 | Team1  |      2 | Team1 | Team2 |
    +-------+--------+--------+-------+-------+
    | game2 | Team2  |      2 | Team1 | Team2 |
    +-------+--------+--------+-------+-------+
    | game3 | Team1  |      6 | Team2 | Team1 |
    +-------+--------+--------+-------+-------+
    

What I've tried so far

for ($i=101; $i<=102; $i++) {

    $stmt = $conn->query('SELECT game, points, result, '.$i.' FROM data');

    echo 'SELECT game, points, '.$i.', result FROM data';

    while($row = mysqli_fetch_array($stmt))
        {
            $result = $row['result'];
            $points = $row['points'];
            $choice = $row[''.$i.''];

                if ($result == $choice) {
                    $total = $total.$points;
                }
        }

        echo $total;      

}
James Patrick
  • 189
  • 1
  • 2
  • 10

1 Answers1

0

As it turns out, you can't simply name the columns of your table numbers without identifiers (`) as was clearly pointed out in this SO article: Can a number be used to name a MySQL table column?

Thanks all.

Community
  • 1
  • 1
James Patrick
  • 189
  • 1
  • 2
  • 10