...

View Full Version : updating mysql table data from another table



mrjameer
11-20-2006, 05:26 PM
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

arne2
11-20-2006, 07:57 PM
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:

<?
//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!

guelphdad
11-20-2006, 11:35 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum