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 ) Link to comment https://forums.phpfreaks.com/topic/131142-solved-adding-values-together-based-on-another-row/ 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. Link to comment https://forums.phpfreaks.com/topic/131142-solved-adding-values-together-based-on-another-row/#findComment-680906 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? Link to comment https://forums.phpfreaks.com/topic/131142-solved-adding-values-together-based-on-another-row/#findComment-680912 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); Link to comment https://forums.phpfreaks.com/topic/131142-solved-adding-values-together-based-on-another-row/#findComment-680914 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? Link to comment https://forums.phpfreaks.com/topic/131142-solved-adding-values-together-based-on-another-row/#findComment-680925 Share on other sites More sharing options...
.josh Posted November 3, 2008 Share Posted November 3, 2008 by removing the number_format Link to comment https://forums.phpfreaks.com/topic/131142-solved-adding-values-together-based-on-another-row/#findComment-680930 Share on other sites More sharing options...
jj20051 Posted November 3, 2008 Author Share Posted November 3, 2008 Thnks All! Link to comment https://forums.phpfreaks.com/topic/131142-solved-adding-values-together-based-on-another-row/#findComment-680934 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. Link to comment https://forums.phpfreaks.com/topic/131142-solved-adding-values-together-based-on-another-row/#findComment-681120 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. Link to comment https://forums.phpfreaks.com/topic/131142-solved-adding-values-together-based-on-another-row/#findComment-681171 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.