/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Sum and If Statements

I am trying to calculate the total worth of lecture courses that an individual has taken. They must attend (cle_signup.attended=’x’) and the course must have a credit worth (cle.accredited=’Yes’).

There are 3 levels of individuals: “1st or 2nd year”, “3rd or above” and “other”.

Each level had a different value showing:
[INDENT]1st or 2nd year = “newmember” value
3rd or above = “cpd & eppm” value
other = no value[/INDENT]

If I remove the if statement, my sum works but I dont get the correct value because I dont have any criteria.

My if statements give no results and no errors.

[code=php]$query = “SELECT SUM(cle.newmember), SUM(cle.cpd), SUM(cle.eppm) FROM cle, cle_signup WHERE cle_signup.attended=’x’ AND cle.accredited=’Yes’ AND (cle_signup.fname like ‘%$trimmed%’ OR cle_signup.lname like ‘%$trimmed%’)”;
$result = mysql_query($query) or die(“Couldn’t execute query: “.mysql_error());
while($rows = mysql_fetch_array($result)){
$year=$rows[‘cle_signup.year’];

if ($year == “1st or 2nd year”)
{
echo “Accredited Total = “.$rows[‘SUM(cle.newmember)’].””;
}
elseif ($year == “3rd or above”)
{
echo “Accredited CPD Total = “.$rows[‘SUM(cle.cpd)’].” & Accredited EPPM Total = “.$rows[‘SUM(cle.eppm)’].””;
}
else
{
echo “”;
}
}[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @beylah 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.17,
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,
)...