Jump to content

Archived

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

jrodd32

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>');
  }

Share this post


Link to post
Share on other sites
check your sql tables and make sure your variables and everythig else match up to the table values etc... check for spelling errors as well

Share this post


Link to post
Share on other sites
Have you defined $officialslist anywhere in the routine that does the while($officials= ... etc)> I only see it in the init_officials_all function.

Ronald   8)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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");

Share this post


Link to post
Share on other sites
you forgot the comman between zip4 and homepage. also just use WHERE CURRENT='TRUE'. You are also running a php function inside an sql statement. The mysql function for substr is substring.

Ray

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.