MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 11th, 2003, 08:14 AM
sarahnavas2003 sarahnavas2003 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 1 sarahnavas2003 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\php

Need help this keeps running an error. Anyone know why?
Thanks

<?php
while($row = mysql_fetch_array($result))
{
?>

Reply With Quote
  #2  
Old April 13th, 2003, 05:48 AM
jaguar_wolf jaguar_wolf is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 8 jaguar_wolf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
try this

PHP Code:
<?
$sql 
"SELECT * FROM `mytable` WHERE `id` = '1'";

db_connect();//connecting mysql db function i wrote

$result mysql_query($sql) or die(mysql_error());

while(
$row mysql_fetch_array($result)){

 
// do some thing here



mysql_close(db_connect());
?>

Reply With Quote
  #3  
Old April 14th, 2003, 10:54 AM
torrent torrent is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 19 torrent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Re: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\php

Quote:
Originally posted by sarahnavas2003
Need help this keeps running an error. Anyone know why?
Thanks

<?php
while($row = mysql_fetch_array($result))
{
?>
Your SQL query is failing. Do what jaguar_wolf says and use the or die mysql_error();. This will display the problem.

Reply With Quote
  #4  
Old July 29th, 2004, 06:00 PM
tim_ver tim_ver is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 7 tim_ver User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
question

I am new to this and have the same error. When I goto put this code in

<?
$sql = "SELECT * FROM `mytable` WHERE `id` = '1'";

db_connect();//connecting mysql db function i wrote

$result = mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_array($result)){

// do some thing here

}

mysql_close(db_connect());
?>

Do I need to remove other code or edit anything? I want to get this right
thanks for the help.


Reply With Quote
  #5  
Old January 21st, 2005, 08:15 PM
denisecamargo denisecamargo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 1 denisecamargo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi all ! I got this code for showing random buttons on my personal weblog. but I keep getting that error. Any help ?

Code:
<? include("config.php");
 $linkcount = 6;
 ?>
 <?
 $result=mysql_query ("SELECT * FROM $table_link ORDER BY RAND() LIMIT $linkcount");
 if ($row=mysql_fetch_array($result)) {
 do {
 $width=$row["width"];
 $height=$row["height"];
 if ($width < 10){
 $insert_width = "";
 } else { $insert_width=" width=\"$width\""; }
 if ($height < 10){
 $insert_height = "";
 } else { $insert_height=" height=\"$height\""; }
 ?>
 <a href="<?=$row["url"]?>" target="new"><img border="0" src="<?=$base_url?><?=$row["image"]?>" alt="<?=$row["name"]?>"<?=$insert_width?><?=$insert_height?>></a>
 <?
 } while($row = mysql_fetch_array($result));
 } else {print "There are no links in this category.";}
 ?>



And this is the include
Code:
<? include ("/home/canela/public_html/fan/random.php") ?>


the buttons are within a subdomain on my personal domain.

Thanks.

Reply With Quote
  #6  
Old January 24th, 2005, 12:04 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 6
Here's what's going on with 'not a valid result resource' errors. Take the following example:

PHP Code:
 $query 'SELECT * from table';
   
   
$result mysql_query($query);
   
   while(
$row mysql_fetch_array($result))
   { echo 
$row['foo']; } 


In the above, the mysql_query() function is sending the specific query to the database and returning a 'resource identifier', which is being set as the value of $result. These are not the results themselves -- if you echo $result at this point, you'll get 'Resource id #x'. The mysql_fetch_array() function in your while loop takes this resource identifier and creates an array of the actual db contents that you can use.

If your mysql_query() function fails to get a resource id, it returns a boolean FALSE instead. FALSE, of course, isn't a resource identifier, so when you try to pass it to mysql_fetch_array(), it will cough up the 'not a valid result resource' error. So all of you are getting failures in your mysql_query() function.

Using 'or die(mysql_error())' at the end of your mysql_query() call, like jaguar_wolf posted, will, instead of setting $result to FALSE, kill the script and, more importantly, return a more descriptive error message.

Probably 80%+ of the time, a failed mysql_query() is caused by a syntax error in the query itself. Be especially mindful of any variables you're using in your query -- if they're not being set correctly, they can cause a syntax error. A failure to connect to the database can also cause mysql_query() to fail, so keep that in mind. Either way, the mysql_error() function will give you more information.
Comments on this post
rootcat agrees: A very detailed post which let me solve the problem.Thanks

Reply With Quote
  #7  
Old January 26th, 2005, 06:47 AM
angryopium angryopium is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 1 angryopium User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 4 sec
Reputation Power: 0
Hello all,
I got a strange case...
I use a getElements method to which I pass the table and the name of the field I want to sort results with...

here's the code:
Code:
function getElements($table, $sort){
 		$query = "SELECT * FROM $table ORDER BY $sort";
 		$connection = mysql_connect($this->HOST, $this->USERNAME, $this->PASSWORD);
 		$SelectedDB = mysql_select_db($this->DBNAME);
 		$result = mysql_query($query) or die(mysql_error()); 
 		$i=0;
 		while ( $element = mysql_fetch_array($result) ) {
 				$elements[$i] = $element;
 			  $i++;
 		}
 		return($elements);
 	}
 

OK... I use this method in a main page:
Code:
require_once("eMgr.php"); // the php class
 $mgr=new eMgr(); // instantiation
 // Management code:
 $groups=$mgr->getElements("gruppi", "descrizione");
 	if (count($groups > 0)){
 	  foreach($groups as $group){
 ?>
   <tr>
 	<td>
 	<td align="center">[mod] - [del]
   </tr>
 <?		
 	  }
 	}
 

and everything is ok...

now I open a new window (javascript) to insert a new group and I use again the same method to fill the options of html select. The code in the new window is:
Code:
require_once("eMgr.php");
 $m = new eMgr();
 $groups = $m->getElements("gruppi","descrizione");
 


the error returned is:
No Database Selected

I really don't know what's wrong! I tryed closing connection and setting $result to NULL .... But the error is always the same!

Any suggestions???

Thx

Reply With Quote
  #8  
Old January 26th, 2005, 09:21 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 10
this sounds like a new question.
You might get better results making a new thread for it.

Reply With Quote
  #9  
Old March 11th, 2008, 08:20 PM
toxinhead toxinhead is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 1 toxinhead User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 6 sec
Reputation Power: 0
GUYS mac

Reply With Quote
  #10  
Old February 15th, 2009, 01:39 AM
Sergiu(^_^) Sergiu(^_^) is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2009
Posts: 2 Sergiu(^_^) User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 m 42 sec
Reputation Power: 0
Cool

Quote:
Originally Posted by sarahnavas2003
Need help this keeps running an error. Anyone know why?
Thanks

<?php
while($row = mysql_fetch_array($result))
{
?>


you might have forgoten a " " space in you query...
I're run into this problem shortly after I watched some vid. tutorials and that was the problem( took me 1 h to figure it out ) .

example:
...
$select = "SELECT X,Y";

$from = "FROM TABLE";

$query = $select.$from;

$result = mysql_query($query);

while($row = mysql_fetch_array($result))
...


so try to put a space before the closing qoute in each query..select,from, etc.

hope this helps

Reply With Quote
  #11  
Old June 27th, 2009, 03:11 PM
Kodiak3000 Kodiak3000 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 1 Kodiak3000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 50 sec
Reputation Power: 0
Thumbs up Thanks!

Quote:
Originally Posted by Madpawn
Using 'or die(mysql_error())' at the end of your mysql_query() call, like jaguar_wolf posted, will, instead of setting $result to FALSE, kill the script and, more importantly, return a more descriptive error message.


Man, that so saved my butt. All it was was a capital letter ('Products' instead of 'products'), and since I didn't write the database, I didn't see it, but without the much clearer error message, I'd have been looking for it all day.

Thanks a ton!

Reply With Quote
  #12  
Old August 30th, 2009, 04:24 PM
BrandNew BrandNew is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 1 BrandNew User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 36 sec
Reputation Power: 0
Similar issue, I have been trying...

to correct it myself using your advice, but since I am relatively new, perhaps I just do not have enough knowledge to see where the problems lie.

The following code -

php Code:
Original - php Code
  1. function symbol_currency(){
  2.  
  3. $symbol_row=mysql_fetch_array(mysql_query("select symbol from site_var where status='1'"));
  4. if($symbol_row['symbol']!='')
  5. return $symbol_row['symbol'];
  6. else
  7. return '$';
  8. }


is returning the error -

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

Any help would be greatly appreciated.

Last edited by Itsacon : August 31st, 2009 at 02:45 AM. Reason: added code-tags

Reply With Quote
  #13  
Old August 31st, 2009, 02:47 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 1,030 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 1980407 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980407 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980407 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980407 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980407 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980407 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980407 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980407 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980407 Folding Title: Super Ultimate Folder - Level 4
Time spent in forums: 1 Week 9 h 13 m 59 sec
Reputation Power: 7
Send a message via ICQ to Itsacon
Most likely, the mysql_query() call is failing for some reason. Split the row into two seperate commands and add error checking in between the query and the result-handling (Never assume a function will go right. Lots of stuff can go wrong).
__________________
This is my code. Is it not nifty?

"The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools."
---Douglas Adams


Join the Itsacon fanclub!    
Zero Tolerance: Spammers banned so far: 564

Reply With Quote
  #14  
Old November 7th, 2009, 03:37 PM
beazleybub beazleybub is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 1 beazleybub User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 21 sec
Reputation Power: 0
Thank you

I know this is an old thread but I am new to php and personally wanted to say thank you to jaguar_wolf.

or die mysql_error(); taught me a new thing!


Reply With Quote
  #15  
Old February 22nd, 2010, 04:24 PM
vanillashake vanillashake is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2010
Posts: 1 vanillashake User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 29 sec
Reputation Power: 0
I had the same error but my problem was in the query:

$sql = "SELECT * FROM table WHERE column1= ' " . $_GET['name'] . " ' ";

I used only column1 = ' . $_GET['name'] . ' when I was suposed to open another set of " ".

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\php


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 7 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek