I'm trying to SUM
multple columns from a table using the follow query.
$res1 = $db->prepare('SELECT sum(kill) as kill,
SUM(death) as death, SUM(assist)as assit FROM eventgame GROUP BY player');
$res1->execute();
while ($row = $res1->fetch(PDO::FETCH_ASSOC)) {
echo '.$row['player'] .$row['kill'] .$row['death'] .$row['assit'].';}
what I'm trying to do is get the total from each player, like:
PLAYER | kill | death | assit
player1 | 10 | 5 | 26
player2 | 5 | 10 | 35
I have been trying this for the last 2 days or so before come here ask for help.
I'm using PDO to connect to my DB.
You really are not preparing a statement with bound parameters, as much as you are running a query. From the mysql-side of things, try something like
SELECT player, sum(kill) as kill, SUM(death) as death, SUM(assist) as assist
FROM eventgame
GROUP BY player
order by player
You group by the column or columns that are not in the aggregate functions (like sum avg count min max etc)