That's approach is really a detour. Use the functions of the database whenever possible.
Do a query like "SELECT SUM(somefield) FROM sometable" and you don't have to do any summing with php.
Your method should work, but I'm not going to try to guess what's wrong. Lets see some code if you insist on having PHP doing tha adding.
Disclamer: It's 3.45am, and I really should be sleeping...