Jump to content


Photo

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


  • Please log in to reply
9 replies to this topic

#1 jrodd32

jrodd32
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 15 September 2006 - 09:25 PM

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

#2 markbett

markbett
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 15 September 2006 - 10:17 PM

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

#3 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 15 September 2006 - 10:18 PM

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)
RTFM is an almost extinct art form, it should be subsidized.

#4 jrodd32

jrodd32
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 18 September 2006 - 03:50 PM

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.

#5 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 18 September 2006 - 03:52 PM

check out this post
http://www.phpfreaks...ic,95376.0.html

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#6 jrodd32

jrodd32
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 18 September 2006 - 05:40 PM

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");


#7 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 18 September 2006 - 06:02 PM

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

#8 jrodd32

jrodd32
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 18 September 2006 - 06:09 PM

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.

#9 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 18 September 2006 - 06:21 PM

you have to tell it which table to look in
...using FROM tablename

so
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
should do the trick

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#10 jrodd32

jrodd32
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 18 September 2006 - 06:24 PM

Yep that was it.

Dumb mistake

Thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users