Jump to content

SUM specific id's and all rows


tribol

Recommended Posts

i'm just trying to get the SUM of votes of two unique id's per query in one specific table. each contestant has three seperate posts that can be voted on and i figured this would do it, just wondering if it looks right.

 

//team 1
function totalVotesOne ($intTotalOneVotes) {
$query="SELECT SUM(totalvotes) as total_one FROM ".DB_DATABASE.".bonusvotes_2010 WHERE bonusvotes_2010.contestantID='2093' AND bonusvotes_2010.contestantID='538' AND bonusvotes_2010.status='Valid'";
$result=mysql_query($query);
$return mysql_num_rows($result);
}

//team two
function totalVotesTwo ($intTotalTwoVotes) {
$query="SELECT SUM(totalvotes) as total_two FROM ".DB_DATABASE.".bonusvotes_2010 WHERE bonusvotes_2010.contestantID='5449' AND bonusvotes_2010.contestantID='2888' AND bonusvotes_2010.status='Valid'";
$result=mysql_query($query);
$return mysql_num_rows($result);
}


//team three
function totalVotesThree ($intTotalThreeVotes) {
$query="SELECT SUM(totalvotes) as total_three FROM ".DB_DATABASE.".bonusvotes_2010 WHERE bonusvotes_2010.contestantID='3460' AND bonusvotes_2010.contestantID='242' AND bonusvotes_2010.status='Valid'";
$result=mysql_query($query);
$return mysql_num_rows($result);
}

 

Link to comment
https://forums.phpfreaks.com/topic/208435-sum-specific-ids-and-all-rows/
Share on other sites

Okay so I've edited the query's a little: (in functions.php)

 

//team one
function totalVotesOne ($intTotalOneVotes) {
$query="SELECT SUM(totalvotes) as total_one FROM ".DB_DATABASE.".bonusvotes_2010 WHERE bonusvotes_2010.contestantID= IN ('2093,538') AND bonusvotes_2010.status='Valid'";
$result=mysql_query($query);
return mysql_num_rows($result);
}

//team two
function totalVotesTwo ($intTotalTwoVotes) {
$query="SELECT SUM(totalvotes) as total_two FROM ".DB_DATABASE.".bonusvotes_2010 WHERE bonusvotes_2010.contestantID= IN ('5449,2888') AND bonusvotes_2010.status='Valid'";
$result=mysql_query($query);
return mysql_num_rows($result);
}


//team three
function totalVotesThree ($intTotalThreeVotes) {
$query="SELECT SUM(totalvotes) as total_three FROM ".DB_DATABASE.".bonusvotes_2010 WHERE bonusvotes_2010.contestantID= IN ('3460,242') AND bonusvotes_2010.status='Valid'";
$result=mysql_query($query);
return mysql_num_rows($result);
}

 

and i'm calling the results from my index.php with:

 

Current Total Votes:<?=$totalVotesOne?>
Current Total Votes:<?=$totalVotesTwo?>
Current Total Votes:<?=$totalVotesThree?>

 

But it's not giving me any results???

 

Don't get it

Current Total Votes:<?=totalVotesThree(1) ?>
Current Total Votes:<?=totalVotesThree(1) ?>
Current Total Votes:<?=totalVotesThree(1) ?>

 

But why are you passing a parameter to the function that you are not even utilizing? Your MySQL is also bad:

 

$query="SELECT SUM(totalvotes) as total_three FROM ".DB_DATABASE.".bonusvotes_2010 WHERE bonusvotes_2010.contestantID IN ('3460,242') AND bonusvotes_2010.status='Valid'"

(Removed the =)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.