tribol Posted July 21, 2010 Share Posted July 21, 2010 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); } Quote Link to comment https://forums.phpfreaks.com/topic/208435-sum-specific-ids-and-all-rows/ Share on other sites More sharing options...
Zane Posted July 21, 2010 Share Posted July 21, 2010 SELECT SUM(totalvotes) as total_three FROM ".DB_DATABASE.".bonusvotes_2010 WHERE bonusvotes_2010.contestantID IN ('3460','242') AND bonusvotes_2010.status='Valid' Quote Link to comment https://forums.phpfreaks.com/topic/208435-sum-specific-ids-and-all-rows/#findComment-1089180 Share on other sites More sharing options...
tribol Posted July 21, 2010 Author Share Posted July 21, 2010 Why does it keep returning errors on this line $return mysql_num_rows($result); Quote Link to comment https://forums.phpfreaks.com/topic/208435-sum-specific-ids-and-all-rows/#findComment-1089190 Share on other sites More sharing options...
Zane Posted July 21, 2010 Share Posted July 21, 2010 because it's an invalid statement. $return must do something to mysql_num_rows; That is assuming you want a variable named $return. Possibly you want return mysql_num_rows() without the dollar sign? Quote Link to comment https://forums.phpfreaks.com/topic/208435-sum-specific-ids-and-all-rows/#findComment-1089194 Share on other sites More sharing options...
tribol Posted July 21, 2010 Author Share Posted July 21, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/208435-sum-specific-ids-and-all-rows/#findComment-1089200 Share on other sites More sharing options...
premiso Posted July 21, 2010 Share Posted July 21, 2010 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 =) Quote Link to comment https://forums.phpfreaks.com/topic/208435-sum-specific-ids-and-all-rows/#findComment-1089250 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.