Page 1 of 1

Warning: mysql_fetch_assoc():

Posted: Sat May 03, 2008 9:41 am
by gaogier
here is my error

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/gaogier/public_html/admin2.php on line 454

Code: Select all

 
function calcitem($calc){
$calc1 = str_replace("calc", "", $calc);
echo '<p><font class="adminheader">Caclulator Item Admin for '.$calc1.'</font></p>';
echo "<TABLE border=\"0\" width=\"89%\" class=monster>\n";
 echo "<TR><TD class=title><center>Item Name</center></td><td class=title><center>Level - XP</center></TD><td class=title><center>Edit</center></TD</TR>\n";
   /* query for monsters */
        $query = "SELECT id, item, members, level, xp FROM ".$calc." ORDER BY level, item ASC";    
        $result = mysql_query ($query);
        while ($row = mysql_fetch_assoc ($result)) { /*error line */
            /* display monsters in a table */
            /* place table row data in 
             * easier to use variables.
             */
             $count = $count + 1; 
    
            $name = $row['item'];   
            $mem = $row['members'];
            if ($mem == "1"){
I know all the code is not there my file is over 20000 char too long

Re: Warning: mysql_fetch_assoc():

Posted: Sat May 03, 2008 3:21 pm
by Kastor
Maybe you have error in SQL query

Code: Select all

if(!$result = mysql_query ($query)) die(mysql_error());

Re: Warning: mysql_fetch_assoc():

Posted: Sat May 03, 2008 3:42 pm
by califdon
Yes, that is most likely. You should always use the format as Kastor has shown, so that the error will be displayed to you. Furthermore, it is almost certain that the error is that there is no value, or an incorrect value, for $calc. So echo that at the top of your function, so you can tell what is happening.

Re: Warning: mysql_fetch_assoc():

Posted: Sat May 03, 2008 4:48 pm
by Christopher
With an SQL statement that simple, either one of "id, item, members, level, xp" is not a valid column name, or $calc (or should it be $calc1 ??) is not a valid table name. You really need to check mysql_errno() after a query and check mysql_error() to see what the problem is. The database server knows much more than we do.