|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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)) { ?> |
|
#2
|
|||
|
|||
|
try this
PHP Code:
|
|
#3
|
|||
|
|||
|
Re: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\php
Quote:
|
|
#4
|
|||
|
|||
|
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. ![]() |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
Here's what's going on with 'not a valid result resource' errors. Take the following example:
PHP Code:
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. |
|
#7
|
|||
|
|||
|
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 |
|
#8
|
||||
|
||||
|
this sounds like a new question.
You might get better results making a new thread for it. |
|
#9
|
|||
|
|||
|
GUYS mac
|
|
#10
|
|||
|
|||
|
Quote:
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 ![]() |
|
#11
|
|||
|
|||
|
Quote:
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! |
|
#12
|
|||||
|
|||||
|
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:
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 |
|
#13
|
||||
|
||||
|
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
![]() |
|
#14
|
|||
|
|||
|
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! ![]() |
|
#15
|
|||
|
|||
|
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 " ". |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\php |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|