Jump to content

Recommended Posts

$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

Link to comment
https://forums.phpfreaks.com/topic/306990-floor-sum-and-group/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.