...

View Full Version : mysql_fetch_array(): supplied argument is not a valid MySQL result resource



hanpedro
06-28-2005, 05:51 AM
I want to compare two dbs data,

<td valign=top>
<?
mysql_select_db($test1[db], $test1[conn]) or die("$test1[db] ??.");
$test1[sql] = " select * from test1_table ";
$test1_result = mysql_query($test1[sql]);
for ($i=0; $row=mysql_fetch_array($test1_result); $i++)
{
echo "[name];
}
?>
</td>
<td>
<?
mysql_select_db($test2[db], $test1[conn]) or die("$test2[db] ??.");
$test2[sql] = " select * from test2_table ";
$test2_result = mysql_query($test2[sql]);
for ($i=0; $row=mysql_fetch_array($test2_result); $i++)
{
echo "[table];
}
?>
</td>

However, the second box shows this..

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in test.php on line 29

chump2877
06-28-2005, 10:16 AM
Change this line:


$test2_result = mysql_query($test2[sql]);

to


$test2_result = mysql_query($test2[sql]) or die(mysql_error());

This will display the MySQL error that you're probably receiving (but was heretofore undetected) with your previous query.....Something is probably wrong with the query syntax, which is the reason why your result source is bad....

Also, do you absolutely need the key following $test1 and $test2 ([sql])? I would try removing it if possible, or perhaps you could reassign the array element to another variable, and see if that helps....

hanpedro
06-28-2005, 10:23 AM
Thanks a lot for your kind comment.

Fou-Lu
06-28-2005, 04:28 PM
In case you still have problems...

I'm wondering by chance if this is because you are crossing databases. Now, I'm not certain on this as I have never needed to cross databases before, but I'm wondering if perhaps the error is being caused by a subsequent call to the initial database. From the looks of it, I'd say no, this isn't the problem, but I'm suprised sometimes by what causes odd results.
So, if you still don't have it working, after your first query, simply run a mysql_close() on the connection and then re-establish it with your new database. Just a thought though.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum