Page 1 of 1

copying multiple row

Posted: Mon Apr 21, 2008 8:20 am
by mosfet83
Hi again :P

i need some advise on how to copy multiple row with mysql and php
first way i can think of is sql statement as below

Code: Select all

INSERT INTO [i]table [/i](column1, column3) SELECT column2, column4 FROM [i]table2 [/i]
but how can i insert my own value into column3 in the same statement? do i have to insert column1 first then use UPDATE to insert column2 value?

second way maybe as below?

Code: Select all

 
$sql = "SELECT * FROM [i]table1[/i]";
$result = mysql_query($sql, $db);
while($row = mysql_fetch_assoc($result)){
   $sql2 = "INSERT INTO [i]table1[/i](column1, column2) VALUE ($row['name'], $row['phone']);
   $result2 = mysql_query($sql2,$db); 
}
 
which one is better? please advise. i have about 4000-10,000 rows per month to be duplicated with certain columns value needed to be changed. thank you.