Jump to content

supplied argument is not a valid MySQL result resource (solved)


Recommended Posts

I used an exact copy of the following code with different variable names in another program and it works fine, however, once i changed the variable names it gives me the error:

Warning:  mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/khsaa.org/subdomains/admin/httpdocs/jerrod/officials/tool_kit_officials.inc on line 141


<?php
  $sport;
  $officialtype="All Current Officials/Referees/Umpires";
  init_officials_all();
  printpage_officials($sport,$officialtype,$officials,$officialslist);
?>

function init_officials_all()
{
   if (!($db = @mysql_connect('localhost', 'username','password')))
   {;
     print 'Temporarily unable to connect to database server. Please try again later.';
     exit;
   }
   mysql_select_db('Scoreboard',$db);
   global $officials;
   $officials=mysql_fetch_array(mysql_query("SELECT officials_complete.* FROM officials_complete where CURRENT=\"TRUE\""));
   global $officialslist;
   $officialslist=mysql_query("SELECT lname, fname, suffix, address, city, state, zip, zip4, homephone, workphone, email WHERE CURRENT=\"TRUE\" order by lname");
}

the error occors at this loop:

while($officials=mysql_fetch_array($officialslist))
  {
      printf('%-60s ',$officials[lname]);
      printf('%-20s ',$officials[address]);
      printf('%-20s ',$officials[city]);
      printf( '%-7s ',$officials[state]);
      printf('%-12s ',$officials[zip.$sp.zip4]);
      printf('%-20s ',$officials[homephone]);
      printf('%-20s ',$officials[workphone]);
      printf('%-30s ',$officials[email]);
      print('<br>');
  }
I thought the global aspect of the variable would take care of needing to have it defined everywhere.

If not, what do I need to put within the function to make the program recognize that it is the same variable as earlier.
I used the mysql_error function and it gave me this error:

You have an error in your SQL syntax near 'WHERE CURRENT="TRUE" and SW=substr("T",49,1) order by lname' at line 1

However, it will print all the fields that I am selecting and starts the list with the appropriate name.

The variable names are all correct spelling and in the correct cases of upper and lower case to match the database.

Here is the line of code:

$officialslist=mysql_query("SELECT lname, fname, address, city, st, zip, zip4 homephone, workphone, email WHERE CURRENT=\"TRUE\" and $sport=substr(\"T\",49,1) order by lname");
Does the same type of syntax apply for the mysql substring function because I need that to check to make sure the official is update with his/her test scores and thus making them eligible to work games.

However, in another function that does not have the substr call I still get the same error even after fixing the comma.
you have to tell it which table to look in
...using FROM tablename

so
[code]
SELECT lname, fname, address, city, st, zip, zip4 homephone, workphone, email FROM yourTable WHERE CURRENT=\"TRUE\" and $sport=substr(\"T\",49,1) order by lname[/code]
should do the trick
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.