onthespot Posted October 18, 2009 Share Posted October 18, 2009 <? $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 More sharing options...
Mchl Posted October 18, 2009 Share Posted October 18, 2009 $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"; Link to comment https://forums.phpfreaks.com/topic/178147-solved-games-played-5/#findComment-939321 Share on other sites More sharing options...
onthespot Posted October 18, 2009 Author Share Posted October 18, 2009 I tired where games played rather than home and away seperately. This does work though, thankyou. Link to comment https://forums.phpfreaks.com/topic/178147-solved-games-played-5/#findComment-939323 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.