Link to home
Start Free TrialLog in
Avatar of katlees
katleesFlag for United States of America

asked on

Count in SQL and PHP with Loop

I have a printout where it is printing a teams schedule of games and the score and if they won or lost if the game has been played.
If they win, a W gets put in the Win Field, if they lose, an L gets put there.

The section of code that shows the output is below as well as the original query to start the loop.

What I need is for the system to count up the number of W's and the number of L's and show the record like
5-1 or 2-9 for the season.
                              
$event_query = "select * from Events WHERE OpponentID > '0' Order By LevelID, StartDate Asc;";
					
echo "<td>$Score</td><td>$Win</td>\n";

Open in new window

Avatar of PranjalShah
PranjalShah
Flag of United States of America image

Do you have win or lose record in the table? I think if you have a column like result which says W or L so

Inside the query loop do one more query for counting Ws and Ls like
//for winnings
SELECT count(*) FROM table_name WHERE teamID=idofthecurrentteam AND result=win

and similar for losing
ASKER CERTIFIED SOLUTION
Avatar of Aviv23
Aviv23
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial