I need to edit some data in MySql using PHP. Due to complications i decided to delete the records with Code IDs of 'XXX', and re-insert the new records by looping the insert query. The code below will picture it.
//the query for delete records
$sql="delete from ppt_test_grind where tstg_id='$_POST[tmplink_id]'";
mysql_query($sql);
//loop though form fields and insert sql
for($ctr=0;$ctr<=4;$ctr++)
{
$sql="insert into ppt_test_cut(
tstc_id,
tstc_sampleno,
tstc_whldiam1,
...
tstc_1ptside,
tstc_3ptside
)
values
(
'$tmplink_id',
'".trim($_POST['sampleno'][$ctr])."',
'".trim($_POST['whldiam1'][$ctr])."',
'".trim($_POST['whldiam2'][$ctr])."',
...
'".trim($_POST['singlept'][$ctr])."',
'".trim($_POST['threept'][$ctr])."'
)";
mysql_query($sql);
}
Now the problem is when they are inserted in reverse order. For example form ['sampleno'][0] wil be the last one on database and form['sampleno'][4] will be first. How could come when the loop inserted the ['sampleno'][0]s first?
I would appreciate what's in your mind.
//the query for delete records
$sql="delete from ppt_test_grind where tstg_id='$_POST[tmplink_id]'";
mysql_query($sql);
//loop though form fields and insert sql
for($ctr=0;$ctr<=4;$ctr++)
{
$sql="insert into ppt_test_cut(
tstc_id,
tstc_sampleno,
tstc_whldiam1,
...
tstc_1ptside,
tstc_3ptside
)
values
(
'$tmplink_id',
'".trim($_POST['sampleno'][$ctr])."',
'".trim($_POST['whldiam1'][$ctr])."',
'".trim($_POST['whldiam2'][$ctr])."',
...
'".trim($_POST['singlept'][$ctr])."',
'".trim($_POST['threept'][$ctr])."'
)";
mysql_query($sql);
}
Now the problem is when they are inserted in reverse order. For example form ['sampleno'][0] wil be the last one on database and form['sampleno'][4] will be first. How could come when the loop inserted the ['sampleno'][0]s first?
I would appreciate what's in your mind.