Need urgent help

Discussion in 'MySQL' started by Rian, Feb 7, 2010.

  1. #1
    Hi Guys

    I need urgent help.

    I am trying to search multiple databases and return the results to one page.

    The databases have the same table and fields.

    I have managed to connect to two databases, but I have problems displaying the results from both databases. I am stuck with the code below and don't know where to any more...

    As the code is, I can search from only one database and not the second.

    <?php
    
    $conn = mysql_connect( 'localhost', 'xxxxx', 'xxxxxxx' );
    mysql_select_db( 'xxxxxxxx', $conn );
    
    $conn2 = mysql_connect( 'localhost', 'xxxxxxxx', 'xxxxxxx' );
    mysql_select_db( 'xxxxxxxxxxx', $conn2 );
    
    $term = $_POST['term'];
    {
    
    $select = mysql_query( "SELECT * FROM data WHERE ID_NUMBER like '%$term%'", $conn);
    $select1 = mysql_query( "SELECT * FROM data WHERE ID_NUMBER like '%$term%'", $conn2);
    
    $coloum = mysql_fetch_array($select)
    ?>
    Code (markup):
    Can anyone please help with the code?
     
    Rian, Feb 7, 2010 IP
  2. aquilax

    aquilax Member

    Messages:
    126
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    33
    #2
    You can try with one cross database query only if the user has access to both databases:

    Something like:
    SELECT * FROM db1.data WHERE ID_NUMBER like '%$term%'
    UNION
    SELECT * FROM db2.data WHERE ID_NUMBER like '%$term%'
    Code (markup):
    If you want to know where the result row came from, you can add one rudimentary field for each select.
     
    aquilax, Feb 7, 2010 IP
  3. Rian

    Rian Well-Known Member

    Messages:
    1,763
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    125
    #3
    Thanks mate, but it doesn't work.
     
    Rian, Feb 7, 2010 IP