php - Sum values in multidimensional array (selecting multiple columns with multiple rows) -


let's have 5 different columns, a, b, c, d, e, , i'm selecting multiple rows:

$result = mysqli_query($conn,"select a,b,c,d,e posts submitter='$user'");  while ($row = mysqli_fetch_assoc($result)){   $ratings[] = $row;  } 

example:

the user has 3 posts, it'll select 3 rows in query.

i want sum of rows' values a (and rest of course).

e.g.

row 1 a value = 4

row 2 a value = 10

row 3 a value = 1

so need sum of 15.


i know use array_sum($ratings) find sum of array if select 1 column (a) can have multiple rows, multi-dimensional right due multiple column values being selected?

you can use sum in query:

select sum(a)      , sum(b)      , sum(c)      , sum(d)      , sum(e) posts submitter = '$user' 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -