How to display 2 different database having the same table format and record format using PHP Mysql?

2 database called Database2009 as well as Database2010, How to arrangement both with same jot down in a single line carrying a same ID Name, Address though opposite columns in Year2009 & Year2010 in a single quarrel as analogous inform regulating PHP MySql….

One thought on “How to display 2 different database having the same table format and record format using PHP Mysql?

  1. Easy!

    <?php
    //connect to the database
    require(‘database2009_connect.php’);
    $result09 = mysql_query("SELECT * FROM `table_name` ORDER BY `id` DESC");

    echo ‘<table><tr><th>ID</th><th>2009 Name</th><th>2009 Address</th><th>2010 Name</th><th>2010 Address</th></tr>’;
    //cycle through every row in 2009 database
    while($row09 = mysql_fetch_array($result09)){
    //replace id with your primary table field
    $id = $row09['id'];
    //connect to 2010 database
    require_once(‘database2010_connect.php’);
    $row2010 = mysql_fetch_array(mysql_query("SELECT * FROM `table_name` WHERE `id`=’$id’"));
    $name09 = $row09['name'];
    $address09 = $row09['address'];
    //conditional statement – if 2009 and 2010 info is different
    if (($row2010['address'] != $row2009['address']) || ($row2010['name'] != $row2009['name'])){
    $address10 = $row10['address'];
    $name10 = $row10['name'];
    }else{
    $address10 = ‘Same’;
    $name10 = ‘Same’;
    }
    echo ‘<tr><td>’.$id.’</td><td>’.$name09.’</td><td>’.$address09.’</td><td>’.$name10.’</td><td>’.$address10.’</td></tr>’;
    }
    echo ‘</table>’;

    This will make a table in the following format:

    ID 2009 Name 2009 Address 2010 Name 2010 Address
    1 My Name 123 Fake St. Same Same
    2 Business2 31 Elm. St. Business3 31 Elm. St.
    etc…

    At least I think that’s what you were asking, its pretty hard to read the question.

    For future reference, this is poor database structure – I’m quite sure you mean two different TABLES having the same table format, in which case the answer is much different.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>