Solved

Count in SQL and PHP with Loop

Posted on 2011-09-09
2
250 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:katlees
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Expert Comment

by:PranjalShah
ID: 36514169
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
0
 
LVL 1

Accepted Solution

by:
Aviv23 earned 500 total points
ID: 36516212
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.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question