Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts

    updating mysql table data from another table

    hi,

    i want to know how i can update a mysql table data of one database using another database.table data.here the columns of both tables are different.both tables have one common field called id.how i can do this.your help will be appreciated.

    thanks
    mrjameer

  • #2
    Regular Coder
    Join Date
    Aug 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you should use two mysql connections, one for each database.
    Store the connection details of the first database in $connect1 and the connection details of the second in $connect2
    You can then open and close connections by using mysql_connect($connect1) and mysql_close($connect1). As they don't use the same names you should make a small php code that reads all the info you need of mysql connect 1 by using SELECT and then use INSERT to put it in the new database (don't forget to close connection 1 and open connection 2 for doing this !
    Good luck!

    SO u use something like the following:
    PHP Code:
    <?
    //WHILE USING FIRST MYSQL CONNECTION
    $tab1="typthenameoftheoriginaltablehere";
    $tab2="typethenameofthenewtablehere";
    $get mysql_query("SELECT * FROM $tab1 ORDER BY id ASC;");

     while (
    $info mysql_fetch_array($get)){

    $tag.="VALUES ($info['field1'],$info['field2'])";

    }

    //OPEN SECOND MYSQL CONNECTION HERE

    $totaltag="INSERT INTO $tab2 $tag";
    mysql_query($totaltag);
    //CLOSE CONNECTION
    ?>
    This is just my idea of how you could do it. The code above is not a copy paste code. It probably has some faults in the syntax etc, it's just to give you an idea of what your code should look like to work! BUT then you have to use the write syntaxes like ' and " etc etc. Probably someone clever who has time to spend on this forum will give you a better code or will correct mine!
    Last edited by arne2; 11-20-2006 at 08:09 PM.

  • #3
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    Quote Originally Posted by mrjameer View Post
    hi,

    i want to know how i can update a mysql table data of one database using another database.table data.here the columns of both tables are different.both tables have one common field called id.how i can do this.your help will be appreciated.

    thanks
    mrjameer
    so show us what you want to update. multiple updates with a single query and a single connection are possible.

    also note that you should be asking your questions in the correct forum, this is a second one posted in php when you should post them in mysql.


  •  

    Posting Permissions

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