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

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Aviv23Connect With a Mentor Commented:
hi there,

Why don't you try:

Select sum(case when win='w' then 1 else 0 end) as wins, count(sid) as total from --tbl--  where ...

(when you do the count specify a primary key field in it rather the * sign, as sessionID or something).

Then you can do the math.
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
All Courses

From novice to tech pro — start learning today.