Warning: mysql_fetch_assoc():

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

Warning: mysql_fetch_assoc():

Post 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
User avatar
Kastor
Forum Newbie
Posts: 24
Joined: Thu May 01, 2008 2:29 am
Location: Grodno, Belarus
Contact:

Re: Warning: mysql_fetch_assoc():

Post by Kastor »

Maybe you have error in SQL query

Code: Select all

if(!$result = mysql_query ($query)) die(mysql_error());
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Warning: mysql_fetch_assoc():

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Warning: mysql_fetch_assoc():

Post 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.
(#10850)
Post Reply