Jump to content

find largest number from arrays in a loop


lJesterl

Recommended Posts

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 :(

Link to comment
Share on other sites

<?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)
");
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.