Jump to content

PHP Count - instances of a certain result - game scores


lakeshoretech

Recommended Posts

PHP/MYSQL - - -  Thank you in advance for any help.  Quick question.  I am calc'ing whether each line db output is a win/loss/tie below.  Outputting $res in each line.    Is there a simple way to COUNT the number of instances where $ res = "win" or loss or tie?

 

I'd like to put an "overall" record at the top of the output.  For example, for a given query, this chosen team's record is x WINS, Y Losses, Z TIES.  Win/Loss/Tie is NOT a field in the db table.

 

I know how to pull the total # of records pulled, but not this.

 

Example

User pulled a certain team to see game scores.

 

7 - 3 - 2 is their record. is what i'm trying to figure out

 

Game      Result      Score    Score opp    Date

game10    WIN *          7            2                blah

game11    LOSS*        2            3                ....

....

 

 //winloss begin works * above is a result of this code
    if ($row['sch_uba_score'] > $row['sch_opp_score'])
        $res = 'Win';
    elseif ($row['sch_uba_score'] < $row['sch_opp_score'])
        $res = 'Loss';
    else
        $res = 'Tie';

// winloss end works

SELECT SUM(IF(score > `score opp`, 1,0)) as win,
SUM(IF(score < `score opp`, 1,0)) as loss,
SUM(IF(score = `score opp`, 1,0)) as tie FROM scores WHERE your_where_condition_here_to_match_the_correct_team...

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.