Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    628
    Thanks
    51
    Thanked 67 Times in 67 Posts

    ORDER BY throws error

    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.
    PHP Code:
    if((int)$_GET['diff'] > && (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;

    //HERE IS THE PROBLEM QUERY
    $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").
    Last edited by djh101; 10-29-2011 at 11:49 PM.
    "Yeah science!"


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •