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 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts

    Import data from tble1 to tble2

    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?

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Assuming they have the same structure and are already created:
    PHP Code:
    $result mysql_query('INSERT INTO `tbl2` SELECT * FROM `tbl1`') or die(mysql_error()); 
    If you need to create the second table:
    PHP Code:
    $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()); 

  • #3
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    Great ! Thx


  •  

    Posting Permissions

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