SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    May 2000
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I'm throwing together a quick message board and have come across a problem. When a message gets displayed, MySQL gets called upon to grab the message from the database called 'forum'. This happens without toruble, but when I connect to mysql again using a different database to get member infomation, MySQL always gives me an error if I try to work with the data. I don't know if I should be using a single SQL statement to use the two databases or not. The code in question:

    Code:
    // MySQL Login
    $u = username;
    $p = password;
    $d = forum;
    $db = mysql_connect("localhost", "$u", "$p") or DIE("Unable to connect to database. Please contact system admin.");
    mysql_select_db("$d",$db) or DIE("Unable to select database. Please contact system admin.");
    
    // 2nd MySQL Login
    $u2 = username;
    $p2 = password;
    $d2 = other_database;
    $db2 = mysql_connect("localhost", "$u2", "$p2") or DIE("Unable to connect to database. Please contact system admin.");
    mysql_select_db("$d2",$db2) or DIE("Unable to select database. Please contact system admin.");
    <snip>

    The script then displays the messages in the thread, and then the member infomation is grabbed:

    Code:
    $members = mysql_query("SELECT * FROM members WHERE username='$author'",$db2);
    $email = mysql_result($members,0,"email");
    But MySQL doesn't like this and says this:

    Warning: Supplied argument is not a valid MySQL result resource in /web/.../www/forum/showmsg.php on line 68
    If someone could help me out with working with more than one database, or can see an error in the code, please let me know

  2. #2
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For the sake of efficeincy you should be using just the one query with the tables joined on username, that way you are saving 1 query to the database.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.

  3. #3
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Highlight the line 68 so we can see what was wrong, such problems I had before, but it could be other thing (beside multiple connections to MySQL)
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  4. #4
    SitePoint Member
    Join Date
    May 2000
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Line 68 is the last line I mentioned (sorry forgot about that):

    Code:
    $email = mysql_result($members,0,"email");
    I only pasted the code responsible for the error. If I put that small bit of code into a new page, with a single database, it works fine. But, I'll go and find out a bit about joins, that may help me out a bit.

    Thanks,
    Andrew.


Bookmarks

Posting Permissions

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