for($i=0;$i<count($_POST['abc']);$i++)
{
if(!empty($qty[$i]))
{
$insert_sql = "INSERT INTO `table1`(`product_id`,`abc`,`qty`)VALUES ('$product_id','$_POST[abc]','$qty[$i]')";
mysqli_query($con,$insert_sql );
}
$sql = mysqli_query($con,"SELECT product_id FROM `table1` where abc='$abc[$i]'");
$row = mysqli_fetch_object($sql);
$id= $row->product_id ;
for($j=0;$j<count($_POST['value']);$j++) {
if(!empty($val[$j]))
{
$insert_sql1 = "INSERT INTO `table2`(`product_id`,`name`,`number`)VALUES ('$id','$name[$j]','$number[$j]')";
mysqli_query($con,$insert_sql1 );
}
}
}
数据必须在两个表中插入第一个表数据正确插入第二个表数据重复多次
for example:
4 row data
need to inserting 1st and 3rd row data
table1 product id is 1001 1st row data
product id is 1002 2nd row data
table2 product id is 1001 value=1
product id is 1001 value=2
product id is 1002 value=3
product id is 1002 value=4
getting the result 1001 value=1
1001 value=2
1001 value=3
1001 value=4
1002 value=1
1002 value=2
1002 value=3
1002 value=4
尝试在for循环中使用for循环插入更多行数据,再在for循环中插入一个数据。
该字段的新功能可以帮助我解决问题