I need to total up values stored in upto 17 columns in the same table using php, and trying to keep the query as small and simple as possible:
table is Setup like so:
| siterun1 | siterun2 | siterun3 | siterun4 | siterun5 | siterun6 | siterun17 |
| 0 | 5 | 4 | 1 | 0 | 0 | 3 |
is there a quick way of writing a query that counts up all the values from column siterun1 all the way upto siterun17 ?
at the moment i started to write out;
SELECT SUM(siterun1) as 'siterun1', SUM(siterun2) as 'siterun2',
SUM(siterun3) as 'siterun3',
(SUM(siterun1) + SUM(siterun2) + SUM(siterun3)) as 'Total'
FROM dataTable WHERE sessionID=1
but this is going to get very big upto 17 columns with the possibility of more at a later date.
basically i need it to add up the columns and echo the result.
any help on this would be great, my above code will work but i'm not sure if its the best approach.