fsoftball 0 Report post Posted May 20, 2005 Hi,I would like to sharea design I am currently using and have you all tell me if it is an optimal way of doing things.First, here is a table (named schedule) in my MySQL database:game_ID Result1 W2 L3 W4 TIn my PHP code I want to get the number of wins (W), losses (L), and ties (T). Here is how I did it: $wins_sql = "SELECT * FROM schedule WHERE result = 'W'";$loss_sql = "SELECT * FROM schedule WHERE result ='L'";$tie_sql = "SELECT * FROM schedule WHERE result ='T'";$num_loss = mysql_num_rows(mysql_query($loss_sql, $conn));$num_wins = mysql_num_rows(mysql_query($wins_sql, $conn));$num_tie = mysql_num_rows(mysql_query($tie_sql, $conn));echo "Overall Record: $num_wins - $num_loss - $num_tie\n"; Are using three different sql statements the best way to do this? If not, can you please provide an example of what would be better? Thanks! Share this post Link to post Share on other sites
Tyssen 0 Report post Posted May 20, 2005 I think you want to do something using GROUP BY: select result, count(*) AS Numberfrom tableGROUP BY resultORDER BY Number;You don't need Number as a field in your table - you're specifying another value to use in your SQL with the AS command. Share this post Link to post Share on other sites
fsoftball 0 Report post Posted May 20, 2005 Yeah!!! That works from a MySQL view point, but I'm not suer what to do with the returned resutlts from a PHP standpoint. Share this post Link to post Share on other sites