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: 4
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: 8
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
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


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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT