jrodd32 Posted September 15, 2006 Share Posted September 15, 2006 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>'); } Quote Link to comment https://forums.phpfreaks.com/topic/20922-supplied-argument-is-not-a-valid-mysql-result-resource-solved/ Share on other sites More sharing options...
markbett Posted September 15, 2006 Share Posted September 15, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/20922-supplied-argument-is-not-a-valid-mysql-result-resource-solved/#findComment-92713 Share on other sites More sharing options...
ronverdonk Posted September 15, 2006 Share Posted September 15, 2006 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) Quote Link to comment https://forums.phpfreaks.com/topic/20922-supplied-argument-is-not-a-valid-mysql-result-resource-solved/#findComment-92719 Share on other sites More sharing options...
jrodd32 Posted September 18, 2006 Author Share Posted September 18, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/20922-supplied-argument-is-not-a-valid-mysql-result-resource-solved/#findComment-94025 Share on other sites More sharing options...
Zane Posted September 18, 2006 Share Posted September 18, 2006 check out this posthttp://www.phpfreaks.com/forums/index.php/topic,95376.0.html Quote Link to comment https://forums.phpfreaks.com/topic/20922-supplied-argument-is-not-a-valid-mysql-result-resource-solved/#findComment-94026 Share on other sites More sharing options...
jrodd32 Posted September 18, 2006 Author Share Posted September 18, 2006 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 1However, 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"); Quote Link to comment https://forums.phpfreaks.com/topic/20922-supplied-argument-is-not-a-valid-mysql-result-resource-solved/#findComment-94085 Share on other sites More sharing options...
craygo Posted September 18, 2006 Share Posted September 18, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/20922-supplied-argument-is-not-a-valid-mysql-result-resource-solved/#findComment-94104 Share on other sites More sharing options...
jrodd32 Posted September 18, 2006 Author Share Posted September 18, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/20922-supplied-argument-is-not-a-valid-mysql-result-resource-solved/#findComment-94108 Share on other sites More sharing options...
Zane Posted September 18, 2006 Share Posted September 18, 2006 you have to tell it which table to look in...using FROM tablenameso[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 Quote Link to comment https://forums.phpfreaks.com/topic/20922-supplied-argument-is-not-a-valid-mysql-result-resource-solved/#findComment-94120 Share on other sites More sharing options...
jrodd32 Posted September 18, 2006 Author Share Posted September 18, 2006 Yep that was it.Dumb mistakeThanks Quote Link to comment https://forums.phpfreaks.com/topic/20922-supplied-argument-is-not-a-valid-mysql-result-resource-solved/#findComment-94124 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.