Forum Moderators: coopster

Message Too Old, No Replies

my simple query needs work :/

         

Greysoul

4:33 pm on Mar 18, 2010 (gmt 0)

10+ Year Member



hi, i'm new to the boards. was hoping i could stop by and get some help and/or find a place to frequently learn/help others.

about my problem: i get an array error in regards to calling the query. 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

i could always just define gp and score, and do the math in php, but then i don't know how to use the sort() function properly to get it to order by the divisional outcome.

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

Greysoul

4:57 pm on Mar 18, 2010 (gmt 0)

10+ Year Member



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());

eelixduppy

5:04 pm on Mar 18, 2010 (gmt 0)



Cool glad you got everything working. And welcome to WebmasterWorld! :)

Greysoul

5:13 pm on Mar 18, 2010 (gmt 0)

10+ Year Member



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.