Solved

Count in SQL and PHP with Loop

Posted on 2011-09-09
2
239 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
2 Comments
 
LVL 8

Expert Comment

by:PranjalShah
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now