lJesterl Posted March 25, 2010 Share Posted March 25, 2010 I have been at this all night and im about to give up but I remember I use to post here. Im helping someone with soemthing but based on how the table is structured its a little more complicated for me to do what im looking for. Basicly in his "matches" table im wanting to find the "team" who has the most games. I don't like the way the matches table is structured i think thats what is throwing it off. The table structure for the matches table is "matchid,winnerid,loserid" there is more but that is all I need. So the teamid isnt in the match table, its either inserted as the winnerid or the loserid. I have tried num_rows, I have tried COUNT(), but i cant get what im looking for because i have to do a while on all the teams and then when i get the list of num_rows it gives me every teams maches. Sorry if im confusing Here is my code so far: $mostgames=mysql_query("SELECT teamid FROM team WHERE ladderid='$ladder' ORDER BY teamid"); while(list($teamid)=mysql_fetch_row($mostgames)){ $getmostgames= mysql_query("select matchid from matches where winnerid='$teamid' or loserid='$teamid'"); $getmostgames = mysql_num_rows($getgames); echo $getmostgames; } thats when it returns "0023022110516" lol Quote Link to comment Share on other sites More sharing options...
ninedoors Posted March 26, 2010 Share Posted March 26, 2010 Can you explain exactly what you are trying to find? And can you post your table structure? Nick Quote Link to comment Share on other sites More sharing options...
Brandon_R Posted March 26, 2010 Share Posted March 26, 2010 <?php $teams = mysql_query(" SELECT teamid FROM team WHERE ladderid = $ladder ORDER BY teamid "); while ($team = mysql_fetch_array($teams)) { $gamesWon = mysql_query(" SELECT matchid FROM matches WHERE winnerid = $team[teamid] "); $gamesWonCount = mysql_num_rows($gamesWon); $gamesLost = mysql_query(" SELECT matchid FROM matches WHERE loserid = $team[teamid] "); $gamesLostCount = mysql_num_rows($gamesLost); echo " Games Won: $gamesWonCount, Games Lost: $gamesLostCount, ToTal Games Played: ($gamesWonCount + $gamesLostCount) "); } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.