Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Count in SQL and PHP with Loop

Posted on 2011-09-09
2
Medium Priority
?
256 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 2000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

In this article, we’ll look at how to deploy ProxySQL.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

704 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