...

View Full Version : Import data from tble1 to tble2



ajloun
02-28-2010, 09:11 PM
Hello

I have two tables.

lets say tble 1 , tble 2

i want to import the data from tble 1 to tble 2 .. both tables in same Database ..
i need to do it in php .. i could do it with silly way .. by make back up , remove tble2 then rename tble1 to same name as tble 2 then import it back to the database from phpmyadmin ..but loooking for a profissinal way with php.

Any idea?

Inigoesdr
02-28-2010, 09:15 PM
Assuming they have the same structure and are already created:

$result = mysql_query('INSERT INTO `tbl2` SELECT * FROM `tbl1`') or die(mysql_error());
If you need to create the second table:

$result = mysql_query('CREATE TABLE `tbl2` LIKE `tbl1`') or die(mysql_error());
$result2 = mysql_query('INSERT INTO `tbl2` SELECT * FROM `tbl1`') or die(mysql_error());

ajloun
02-28-2010, 09:41 PM
Great ! Thx



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum