Justafriend Posted March 29, 2018 Share Posted March 29, 2018 $dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password); foreach($dbh->query('SELECT PlayerName, floor(((SUM(PScoreAlt) + SUM(PscoreS)) /1000 )*3) + floor(((SUM(ScoreDiffAlt) + SUM(PdiffS)) /500)*2) + floor(SUM(PScoreReg /1500))*3 + floor(Sum(scoredifreg /1500))*2 + SUM(prereg) + SUM(st) + SUM(hb) + SUM(Sbonus) AS BB, floor(((SUM(PScoreAlt) + SUM(PscoreS)) /1000 )*3) + floor(((SUM(ScoreDiffAlt) + SUM(PdiffS)) /500)*2) + floor(SUM(PScoreReg /1500))*3 + floor(Sum(scoredifreg /1500))*2 + SUM(prereg) + SUM(st) + SUM(hb) + SUM(Sbonus) + SUM(Ballots) AS TB, SUM(Ballots) AS PB FROM spplayer Group by PlayerName ') as $row) { $total4 = $row['PB']; $total5 = $row['BB']; $total6 = $row['TB']; Ok from the above code is used to generate a total of ballots awarded based on the conditions Now the catch is if i add a group by and echo it the total doesn't match what is there now and i have figured out why BUT i need a way to get the totals to match, The flaw is if i use just this part for an example floor(((SUM(PScoreAlt) + SUM(PscoreS)) /1000 ) if the totals are jane 1100 the floor would be 1 joe 1400 the floor would be 1 sam 1500 the floor would be 1 moe 1300 the floor would be 1 but the issue is even though the total is 4 it is giving me a floor of 5 as the sum of the four totals is 5300 with a floor of 5 What i am trying to do is figure out a way of getting a correct total of all the people so it would be floor(1100/1000)+floor(1400/1000)+floor(1500/1000)+floor(1300/1000) any help would be greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/306990-floor-sum-and-group/ Share on other sites More sharing options...
requinix Posted March 29, 2018 Share Posted March 29, 2018 What you're doing now is flooring the sum. What you want to be doing is summing the floor. All you have to do is rearrange those function calls. Quote Link to comment https://forums.phpfreaks.com/topic/306990-floor-sum-and-group/#findComment-1557501 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.