Jump to content

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


jrodd32

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.