I am trying to insert values into table from two arrays. I need to insert corresponding values from array1 and array2 into table as a row. ie, The table row looks like:
value1, array1[0], array2[0] ...
value1, array1[1], array2[1] ...
I tried doing it with two foreach loop. But the value inside the innerloop is repeating. Here is my code:
<?php
$servicetype=$_POST['servicetype'];
$serviceamt=$_POST['amount'];
foreach($servicetype as $sertype)
{
foreach($serviceamt as $seramt)
{
$amcinsert2=mysql_query("insert into amc_service_types (amc_service_id,service_type,service_amount) values('$id','$sertype','$seramt')");
break;
}
}
?>
When I execute this, the table will look like:
value1, array1[0], array2[0] ...
value2, array1[1], array2[0] ...
value3, array1[2], array2[0] ...
I didn't understand where should I change my code. Can anyone help me..
forloop insteadVALUE1everytime, you must insert it statically, but why array2 is giving wrong result i dont know....