SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict rwar's Avatar
    Join Date
    Sep 2001
    Location
    PF / RS / BR
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    select in two databases (MySQL)

    I have a challenge. How can I do a select in two databases?

    Details: I have a table pecaspedido (codorder, codclient, codproduct, value) in each database. The table can have the same client in both tables, and of course in both databases, because he (the client) could ordered some products in both systems.

    What I want is to put the results (the clients) in a combobox (a html <select></select>), but in some way that the clients appear only one time, and this is what I'm not obtaining.

    My code is like below, demonstrating that I'm searching in both systems:
    PHP Code:
    [font=Courier New]<select name="INT_codcomissionado">
      <option value="Todos">Todos os comissionados</option>
    <?php
       $QRY_comissionadosintra 
    mysql_query"SELECT DISTINCT CodCli
                                               FROM pedidos
                                               WHERE TipoPed IS NULL
                                               AND DataEnvio>='
    $DAT_datainicio'
                                               AND DataEnvio<='
    $DAT_datafim'
                                               AND SitPed='Enviado'"
    $conexao );

       
    $QRY_comissionadosrastre mysql_query"SELECT DISTINCT CodCli
                                                FROM pedidos
                                                WHERE TipoPed IS NULL
                                                AND DataEnvio>='
    $DAT_datainicio'
                                                AND DataEnvio<='
    $DAT_datafim'
                                                AND SitPed='Enviado'"
    $link );

       while( 
    $RES_comissionados mysql_fetch_array$QRY_comissionadosintra ))
       {
          
    $INT_codcomissionado $RES_comissionados['CodCli'];
          
    $STR_nomecomissionado nomecli$INT_codcomissionado$conexao );
    ?>
          <option value="<?php echo $INT_codcomissionado?>"><?php echo $STR_nomecomissionado?></option>
    <?php
       
    }

       while( 
    $RES_comissionados mysql_fetch_array$QRY_comissionadosrastre ))
       {
          
    $INT_codcomissionado $RES_comissionados['CodCli'];
          
    $STR_nomecomissionado nomecli$INT_codcomissionado$conexao );
    ?>
          <option value="<?php echo $INT_codcomissionado?>"><?php echo $STR_nomecomissionado?></option>
    <?php
       
    }
    ?>
    </select>
    How can I do that? I cannot use DISTINT or INNER JOIN 'cause the data are in two systems.

    Thanks for any help.[/font]
    php? mysql? apache? That's it.

  2. #2
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT column FROM databasename.tablename

  3. #3
    SitePoint Addict rwar's Avatar
    Join Date
    Sep 2001
    Location
    PF / RS / BR
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thansk for the answer, Phil.Roberts, but another problem raised: the databases are in different servers...
    php? mysql? apache? That's it.

  4. #4
    SitePoint Addict Resident Evil's Avatar
    Join Date
    May 2003
    Location
    Barrow
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    like

    PHP Code:

    $query 
    "SELECT omg.table1, omg.table2 FROM table1, table2"
    iirc

  5. #5
    SitePoint Addict rwar's Avatar
    Join Date
    Sep 2001
    Location
    PF / RS / BR
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Resident Evil, I have tried putting the code that Phil.Roberts posted here, and then yours. Both codes don't do nothing, because they are in separated servers, each one together with its respective database. Can you understand?
    php? mysql? apache? That's it.

  6. #6
    SitePoint Member
    Join Date
    Mar 2004
    Location
    Oslo, Norway
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you have to do two separate queries, one to each server, and then manually loop and compare the different results with 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
  •