SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist dscriptor's Avatar
    Join Date
    Oct 2005
    Location
    in front of my computer
    Posts
    571
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question i need a single data from other database

    hi all,

    i have this table in my applicants.php page.

    ID | NAME | EMAIL | CITY | DATE | LEVEL |
    now, im populating the above table using :

    PHP Code:
    While ($row mysql_fetch_row($mysql_result))

         
    //some code here to populate the table...

    but the problem is, the column Level, the data will be coming from another database....

    can anyone give me idea how will i get the data from another database while the table is being populated by another query...

    anyone?...please help...thanks!
    happy is the man that finds wisdom....wisdom in {PHP}.


  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    Another database or another table within the existing database?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Evangelist dscriptor's Avatar
    Join Date
    Oct 2005
    Location
    in front of my computer
    Posts
    571
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    another database....
    happy is the man that finds wisdom....wisdom in {PHP}.


  4. #4
    SitePoint Evangelist
    Join Date
    Apr 2003
    Location
    North Carolina, USA
    Posts
    415
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're using a DB abstraction layer class, then just create a new link. Something like:

    $link = {original MySQL connection link here}
    $otherLink = new Database(...);

    Otherwise, the above can be done by another call to mysql_connect, mysql_select_db, etc.:

    $otherLink = mysql_connect(...);

    Does that help or do you need more specific information?

  5. #5
    SitePoint Evangelist dscriptor's Avatar
    Join Date
    Oct 2005
    Location
    in front of my computer
    Posts
    571
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can you give sample code...thanks!
    happy is the man that finds wisdom....wisdom in {PHP}.


  6. #6
    SitePoint Evangelist
    Join Date
    Apr 2003
    Location
    North Carolina, USA
    Posts
    415
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is not complete code, but here you go:

    Code:
    $link = mysql_connect(...);
    
    if (! $link) {
        die("Could not connect to the database.");
    }
    
    if (! mysql_select_db(... , $link)) {
        die("Could not select the database.");
    }
    
    $link2 = mysql_connect(<another host>);
    
    // Repeat what you did with $link to $link2, etc...
    
    $result = mysql_query(..., $link);
    
    while ($row = mysql_fetch_assoc($result)) {
        // Extract/manipulate data as you wish.
    
        $result = mysql_query("INSERT INTO blah VALUES (...)", $link2);
    }
    I think that will work. Perhaps there is a more efficient way but that's the way I would do it.

  7. #7
    SitePoint Evangelist dscriptor's Avatar
    Join Date
    Oct 2005
    Location
    in front of my computer
    Posts
    571
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, at least, i now have the idea...i'll just examine it...thanks again..
    happy is the man that finds wisdom....wisdom in {PHP}.



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
  •