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

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

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.