Jump to content

[SOLVED] games played 5


onthespot

Recommended Posts

<?

$fifa09="SELECT `user`, (`home_games_played` + `away_games_played`) AS `games_played`,
(((`home_goals_for` + `away_goals_for`)-(`home_goals_against` + `away_goals_against`))/(`home_games_played` + `away_games_played`)) AS `avg_goal_difference`
FROM `$tableName`
ORDER BY `avg_goal_difference` DESC";

$fifa09stats = mysql_query($fifa09);

$i = 0;

while($row=mysql_fetch_assoc($fifa09stats))

{
if($row['games_played'] >= 5){

?>


<tr>
<td><? echo ++$i;?></td>
<td><? echo $row['user'];?></td>
<td><? echo $row['avg_goal_difference'];?></td>
</tr>


<?
}
}
?>

 

Ok so this returns all users that have played 5 games.

Problem is that if i add LIMIT 5 on the end, because it needs 5 games, i could end up with less than 5.

Obviously this is because it returns the 5 best goal difference rows, but if i then use php to limit to just users that have played 5 games then i will lose some of them and could end up with less than 5 rows returned.

Any ideas how i can get around this? thankyou

Link to comment
https://forums.phpfreaks.com/topic/178147-solved-games-played-5/
Share on other sites

$fifa09="SELECT `user`, (`home_games_played` + `away_games_played`) AS `games_played`,
(((`home_goals_for` + `away_goals_for`)-(`home_goals_against` + `away_goals_against`))/(`home_games_played` + `away_games_played`)) AS `avg_goal_difference`
FROM `$tableName`
WHERE
`home_games_played` + `away_games_played` >= 5
ORDER BY `avg_goal_difference` DESC";

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.