php and mysql copy record from one table to another php and mysql copy record from one table to another php php

php and mysql copy record from one table to another


INSERT INTO archive_tableSELECT * FROM original_table WHERE id = 1

simple as that.

If tables have different column number, other layout etc., you will have to specify columns :too

INSERT INTO archive_table(field1, field2, field3)SELECT field7, field8, field9 FROM original_table WHERE id = 1


INSERT INTO new_table SELECT id FROM old_table

This is best practice to move one table row from any table to required table.


while($i<(count($row)-1))    {        $sql.="'".$row[$i]."',";    }    $i=$i+1;

You have to do $i=$i+1; inside the loop...

But,

INSERT INTO archive TABLESELECT FROM original_table WHERE id = 1

is the best way to do ;)