unrelenting Posted August 23, 2008 Share Posted August 23, 2008 I need to do some adding in my query or maybe afterwards would be better. I have a table consisting of a football schedule. It contains columns of year, date, opponent, location, win_loss, points_for, and points_against, etc. I want to create a query that will allow me to display for instance: Your team has played this team 26 times and have a 18-11-1 record all-time against them. What I need is the total times that 'this team' (which would be how many times they are listed as opponent) has played us and even more total the wins and losses via the win_loss column. The win loss column consists of a 0 for a loss, a 1 for a win and a 2 for a tie. Link to comment https://forums.phpfreaks.com/topic/121047-solved-how-to-count-and-total-data-from-database-query/ Share on other sites More sharing options...
Fadion Posted August 23, 2008 Share Posted August 23, 2008 I would go for something like this: <?php $wins = 0; $loss = 0; $tie = 0; $results = mysql_query("SELECT win_loss FROM schedule WHERE opponent='someteam'"); $total = mysql_num_rows($results); while($values = mysql_fetch_array($results)){ if($values['win_loss'] == 0){ $loss++; } if($values['win_loss'] == 1){ $wins++; } if($values['win_loss'] == 2){ $tie++; } } echo "Your team has played $total times and have a $wins-$loss-$tie record all-time"; ?> I can't think of a better way, but maybe someone else can contribute. Link to comment https://forums.phpfreaks.com/topic/121047-solved-how-to-count-and-total-data-from-database-query/#findComment-623975 Share on other sites More sharing options...
unrelenting Posted August 23, 2008 Author Share Posted August 23, 2008 I would go for something like this: <?php $wins = 0; $loss = 0; $tie = 0; $results = mysql_query("SELECT win_loss FROM schedule WHERE opponent='someteam'"); $total = mysql_num_rows($results); while($values = mysql_fetch_array($results)){ if($values['win_loss'] == 0){ $loss++; } if($values['win_loss'] == 1){ $wins++; } if($values['win_loss'] == 2){ $tie++; } } echo "Your team has played $total times and have a $wins-$loss-$tie record all-time"; ?> I can't think of a better way, but maybe someone else can contribute. That is nice. I wish I could think things through that well. Thank you. Link to comment https://forums.phpfreaks.com/topic/121047-solved-how-to-count-and-total-data-from-database-query/#findComment-623982 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.