Jump to content

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 =)

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.