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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Posts
    189
    Thanks
    1
    Thanked 0 Times in 0 Posts

    mysql_fetch_array() Error

    I am trying to make a rank system(i already have 4 other working ones, but this one is a little different).. im getting this error:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/html/clanranks.php on line 65

    The script is:

    PHP Code:
    <?
    $clanid 
    $_GET['clanid'];

    $clanquery mysql_query("SELECT * FROM clans WHERE clanid='$clanid' ORDER BY money_contrib DESC,name LIMIT 0 , 50");
    $clanownquery mysql_query("SELECT * FROM clans_owned WHERE id='$clanid'");
    $clanownrow mysql_fetch_array($clanownquery);


    echo 
    "<table align=\"left\" border=\"1\" width=\"400\" cellspacing=\"0\" cellpadding=\"3\">\n";
    echo 
    "<th>&nbsp;</th><th><font size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">Username</th><th><font size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">Money Contributed</th>";
    while(
    $clanrow mysql_fetch_array($clanquery)){
    $rank += 1;



    echo 
    "<tr height=\"15\"><td width=\"20\"><font size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">$rank</td><td><a href=\"Login_System_v.2.0/userinfo.php?user=$uname\"><font size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">$uname</a></td><td align=\"right\"><font size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">$money</td></tr>\n";
    }
    echo 
    "</table><br>\n";
    echo 
    "<center><a href=\"http://darkvisions.net/clans.php?leader=".$clanownrow['leader']."\">Back</a></center>";

    ?>
    Line 65 is:
    PHP Code:
    while($clanrow mysql_fetch_array($clanquery)){ 
    Please help.

  • #2
    New Coder
    Join Date
    Apr 2006
    Location
    UK
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The error will be with this query:
    PHP Code:
    $clanquery mysql_query("SELECT * FROM clans WHERE clanid='$clanid' ORDER BY money_contrib DESC,name LIMIT 0 , 50"); 
    I think with the ",name" part. It doesn't look like it should be there.
    But in the future, put "or die()"s in your code after queries, in the development phase only at the least.

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Location
    Brasília, Brazil
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Echo the query:
    PHP Code:
    <?
    $clanquery 
    mysql_query("SELECT * FROM clans WHERE clanid='$clanid' ORDER BY money_contrib DESC,name LIMIT 0 , 50");
    echo 
    $clanquery;
    exit;
    Then try the query directly at the mysql prompt or phpMyAdmin.

  • #4
    Regular Coder
    Join Date
    May 2004
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts
    maybe $clanid should be double-quoted not single. (that is just a guess so please don't beat me up on it).

    PHP Code:
    $clanquery mysql_query("SELECT * FROM clans WHERE clanid='$clanid' ORDER BY money_contrib DESC,name LIMIT 0 , 50"); 
    or you could concat it:

    PHP Code:
    $clanquery mysql_query("SELECT * FROM clans WHERE clanid='" $clanid ."' ORDER BY money_contrib DESC,name LIMIT 0 , 50"); 
    I suggested it because a WHERE statement is usually the first place a query can go wrong.

    jmtc
    c.c.

  • #5
    Regular Coder
    Join Date
    Jan 2006
    Posts
    189
    Thanks
    1
    Thanked 0 Times in 0 Posts
    cdwhalley.com was right, the ',name' part shouldnt have been there, its fixed now, thanks a lot for your suggestions


  •  

    Posting Permissions

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