Greysoul Posted March 18, 2010 Share Posted March 18, 2010 i'm guessing its because i have it defining gp and score, and then using the two in a math problem directly after. if this is wrong, how would i go about correcting it? fyi... gp=games played, its tallying the amount of times the player is listed to say how many games they played in. score=a score of kills after deaths, its just a number spg=of course is average score per games played in function pspg(){ $score=mysql_query("SELECT *, COUNT(Player) AS gp, SUM(Score) AS score, (score/gp) AS spg FROM Scorecard WHERE score > 0 GROUP BY Player ORDER BY spg DESC Limit 0,10"); echo "<table>"; echo "<tr> <th class='th'>Rank</th> <th class='th'>Pilot</th> <th class='th'>Clan</th> <th class='th'>GP</th> <th class='th'>SPG</th></tr>"; while($ps=mysql_fetch_array($score)){ echo "<tr>"; echo "<td class='tdp'>" . ++$i . "</td>"; echo "<td class='tdp'>" . '<a href=o.php?p=' . $ps['Player'] . '>' . $ps['Player'] . '</a>' . "</td>"; echo "<td class='tdp'>" . '<a href=o.php?c=' . $ps['Clan'] . '>' . $ps['Clan'] . '</a>' . "</td>"; echo "<td class='tdp'>" . $ps['gp'] . "</td>"; echo "<td class='tdp'>" . round($ps['spg'], 2) . "</td>"; echo "</tr>"; } echo "</table>"; echo "<br>"; } Link to comment https://forums.phpfreaks.com/topic/195700-can-anyone-tell-me-whats-wrong-with-my-query/ Share on other sites More sharing options...
schilly Posted March 18, 2010 Share Posted March 18, 2010 are you getting an error? $score=mysql_query("SELECT *, COUNT(Player) AS gp, SUM(Score) AS score, (score/gp) AS spg FROM Scorecard WHERE score > 0 GROUP BY Player ORDER BY spg DESC Limit 0,10") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/195700-can-anyone-tell-me-whats-wrong-with-my-query/#findComment-1028180 Share on other sites More sharing options...
Greysoul Posted March 18, 2010 Author Share Posted March 18, 2010 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/greysoul/public_html/o/leaders.php on line 99 and if i change to mysql error... Unknown column 'gp' in 'field list' so yeah its pulling from the table in that division instead of the alias i assigned Link to comment https://forums.phpfreaks.com/topic/195700-can-anyone-tell-me-whats-wrong-with-my-query/#findComment-1028182 Share on other sites More sharing options...
Greysoul Posted March 18, 2010 Author Share Posted March 18, 2010 nevermind, figured it out! $score=mysql_query("SELECT *, Count(Player) AS gp, (SUM(Score) / COUNT(Player)) AS spg FROM Scorecard WHERE Score > 0 GROUP BY Player ORDER BY spg DESC Limit 0,10") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/195700-can-anyone-tell-me-whats-wrong-with-my-query/#findComment-1028184 Share on other sites More sharing options...
Greysoul Posted March 18, 2010 Author Share Posted March 18, 2010 i just realized later on i will need to set a minimum of games played..like when there's 10 games played i'd need only players with a minimum of 4 games played to be eligible to be shown. if i change my where clause to...WHERE gp > 3...it just says gp is an unknown column. if i say WHERE Count(Player) > 3..it says invalid group function or something. Link to comment https://forums.phpfreaks.com/topic/195700-can-anyone-tell-me-whats-wrong-with-my-query/#findComment-1028210 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.