/    Sign up×
Community /Pin to ProfileBookmark

trying to get SUM to work….asap

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. This is in my functions.php page

[code=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);
}

[/code]

and i’m calling from index.php with this:

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

to no avail, i get no results???

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@tirnaJul 21.2010 — 1) I assume you have confirmed you have a connection to the database established before running the query.

2) Why are you returning the number of rows in the query's result set, [B]which will always = 1 with your query[/B], and not the value of the sum of votes?

3) when calling each function, you need to echo the function's output where it is called for the output to appear.
Copy linkTweet thisAlerts:
@NogDogJul 21.2010 — Your functions are all always going to return 1, as mysql_num_rows() for that type of query will always find one result row. You instead need to use mysql_result() or one of the mysql_fetch_*() functions to get that actual value of total_one, _two, or _three and return that.
×

Success!

Help @j2eee spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...