jj20051 Posted November 3, 2008 Share Posted November 3, 2008 I Have 3 Rows, User, Approved, and Earnings. I Want To Make A Script That Will Add All The Values Of Earnings Together Based On Only Approved Users. ( I Only Want to Add The Earnings Together On Users that Are Approved ) Quote Link to comment Share on other sites More sharing options...
peranha Posted November 3, 2008 Share Posted November 3, 2008 SELECT SUM(Earnings) FROM table WHERE Approved = "approved"; Something like that would work. Quote Link to comment Share on other sites More sharing options...
jj20051 Posted November 3, 2008 Author Share Posted November 3, 2008 Here Is What I Came Up With Based Upon The Statement Above: $refer = mysql_query("SELECT SUM(uCash) FROM users WHERE uReferrer = 1") or die(mysql_error()); echo $refer; I Get: Resource id #3 Witch Basically Says There Are 3 Rows In The Database, Witch Their Are.... What Is Wrong? Quote Link to comment Share on other sites More sharing options...
Andy-H Posted November 3, 2008 Share Posted November 3, 2008 $refer = mysql_query("SELECT SUM(uCash) as Earns FROM users WHERE uReferrer = 1") or die(mysql_error()); $row = mysql_fetch_object($refer); echo number_format($row->Earns); Quote Link to comment Share on other sites More sharing options...
jj20051 Posted November 3, 2008 Author Share Posted November 3, 2008 Now I Have One Last Small Problem, How do I Keep It From Rounding Up or Down? Quote Link to comment Share on other sites More sharing options...
.josh Posted November 3, 2008 Share Posted November 3, 2008 by removing the number_format Quote Link to comment Share on other sites More sharing options...
jj20051 Posted November 3, 2008 Author Share Posted November 3, 2008 Thnks All! Quote Link to comment Share on other sites More sharing options...
Andy-H Posted November 3, 2008 Share Posted November 3, 2008 You can also use number_format($row->Earns, 2); Which will round it to 2 decimal places. Assuming your working with currency. Doesnt haveto be 2 tho, can be any number. Quote Link to comment Share on other sites More sharing options...
.josh Posted November 3, 2008 Share Posted November 3, 2008 ...or they could just leave it out altogether, seeing as how the OP made no indication that formatting was an issue. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.