Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    91
    Thanks
    19
    Thanked 0 Times in 0 Posts

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

    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

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,768
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Change this line:

    PHP Code:
    $test2_result mysql_query($test2[sql]); 
    to

    PHP Code:
    $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....
    Last edited by chump2877; 06-28-2005 at 09:19 AM.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    New Coder
    Join Date
    Jun 2005
    Posts
    91
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Thanks a lot for your kind comment.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •