lakeshoretech Posted November 13, 2010 Share Posted November 13, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/218544-php-count-instances-of-a-certain-result-game-scores/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 13, 2010 Share Posted November 13, 2010 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... Quote Link to comment https://forums.phpfreaks.com/topic/218544-php-count-instances-of-a-certain-result-game-scores/#findComment-1133718 Share on other sites More sharing options...
lakeshoretech Posted November 13, 2010 Author Share Posted November 13, 2010 Brilliant. Issue resolved. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/218544-php-count-instances-of-a-certain-result-game-scores/#findComment-1133734 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.