Hi,
i want to duplicate rows in a table.
i got this for example:

what im trying to do is duplicate all rows in the same table.
what i got so far is:
ans_id is auto increment.
what i want to do while inserting the rows is find the MAX(ans_q_id) and add +1 one to it and the +1 is for 3 rows ,then the other 3 rows will will be +1 too
so the new ans_q_id + the old one will be like that:
33
33
33
34
34
34
35
35
35
36
36
36
thanks
i want to duplicate rows in a table.
i got this for example:

what im trying to do is duplicate all rows in the same table.
what i got so far is:
Code:
$sql=mysql_query("SELECT `ans_id`, `ans_caption`, `ans_position`, `ans_su_id`, 'ans_q_id' FROM `MY_TABLE` where ans_su_id='2'");
$row=mysql_fetch_assoc($sql);
$num=mysql_num_rows($sql);
for ($i=1; $i<=$num; $i++)
{
$ans_caption= $row['ans_caption'];
$ans_position= $row['ans_position'];
$ans_su_id= $row['ans_su_id'];
$ans_q_id= $row['ans_q_id'];
$copy_AM=mysql_query("INSERT INTO `MY_TABLE`
(`ans_id`, `ans_caption`, `ans_position`, `ans_su_id`, `ans_q_id`)
VALUES
('','$ans_caption','$ans_position','$suid','$ans_q_id')")or die(mysql_error());
}
what i want to do while inserting the rows is find the MAX(ans_q_id) and add +1 one to it and the +1 is for 3 rows ,then the other 3 rows will will be +1 too
so the new ans_q_id + the old one will be like that:
33
33
33
34
34
34
35
35
35
36
36
36
thanks
Comment