|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
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
|
![]() |
| 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 |
|
|
|
|