View Full Version : Resolved ORDER BY throws error

10-29-2011, 11:46 PM
mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

This error is thrown when I place an ORDER BY statement into my query. The table column exists (it's the same column I'm selecting from) and it works fine without ORDER BY. Any ideas?

Here's the code. The problem sections are $query = and $row = , the rest is just there for context.

if((int)$_GET['diff'] > 0 && (int)$_GET['diff'] < 4) $diff = "AND diff='".$_GET['diff']."'";
else $diff = "";

$numrows = mysql_num_rows(mysql_query("SELECT * FROM scores WHERE game='$game' ".$diff)) or err(mysql_error());
if(((int)$_GET['page']-1)*10 >= $numrows) $limit = 0;
else $limit = ((int)$_GET['page']-1)*10;

$query = mysql_query("SELECT * FROM scores WHERE game='$game' ".$diff." ORDER BY scores DESC LIMIT $limit,10");
echo "<total num='".$numrows."' />\n";
for($i=$limit;$row = mysql_fetch_assoc($query);++$i){
echo "<score num='".$i."' val='".$row['score']."' fbid='".$row['fbid']."' />\n";

...and of course I would resolve my own problem right after making a post. scores is the table, the score row is just called score (no "s").