dpcampan Posted May 5, 2013 Share Posted May 5, 2013 Hi all, can any of you wizards help me with a question. I am trying to make a pub quz scoreboard and i am a bit stuck totalling up the round scores. I have a table that stores 'teamid', 'teamname', and then their round scores 'round01', 'round02'..... I can pull all of this data out of the database and format as an html table but i'm stuck on getting their total score. I want it to be automatically generated from their round scores and dont want to have to input it manually.Here is my code so far $query = "SELECT * from scoreboard ORDER BY teamid DESC"; $data = mysqli_query($dbc, $query); echo '<table align="center" table border="1" bordercolour="#00778f" cellpadding="5">'; echo '<tr> <th>Team Name</th> <th>1</th> <th>2</th> <th>3</th> <th>score</th> </tr>'; while ($row = mysqli_fetch_array($data)) echo ' <td>' . $row['teamname'] . '</td> <td>' . $row['round01'] . '</td> <td>' . $row['round02'] . '</td> <td>' . $row['round03'] . '</td> <td>' . $row['round01'+'round02'+'round03'] . '</td> </tr>'; echo '</table>'; i know that <td>' . $row['round01'+'round02'+'round03'] . '</td> is wrong but it gives you the idea of what i want it to do. any help would be greatly appreciated.Darren Link to comment https://forums.phpfreaks.com/topic/277670-sum-of-values/ Share on other sites More sharing options...
Barand Posted May 5, 2013 Share Posted May 5, 2013 $query = "SELECT teamid, teamname, round1, round2, round3, (round1+round2+round3) as total from scoreboard ORDER BY total DESC"; But better to correctly normalize your data Link to comment https://forums.phpfreaks.com/topic/277670-sum-of-values/#findComment-1428445 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.