...

View Full Version : mysql_fetch_array() Error



king2k5
05-02-2006, 08:46 PM
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:



<?
$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:

while($clanrow = mysql_fetch_array($clanquery)){

Please help.

cdwhalley.com
05-02-2006, 10:02 PM
The error will be with this query:


$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.

Kakao
05-02-2006, 11:24 PM
Echo the query:


<?
$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.

ClubCosmic
05-02-2006, 11:26 PM
maybe $clanid should be double-quoted not single. (that is just a guess so please don't beat me up on it).


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

or you could concat it:


$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.

king2k5
05-03-2006, 12:18 AM
cdwhalley.com was right, the ',name' part shouldnt have been there, its fixed now, thanks a lot for your suggestions :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum