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:
- Does Gary's choice (Column 4) equal the Result (Column 2)?
- If so, add the points for that game (Column 3) to variable $total.
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;
}