I have 1 variable
$last_id
and 4 Arrays:
$outA Array ( [0] => 1 [1] => 2 [2] => 4 [3] => 5 )
$outB Array ( [0] => 1 [1] => 1 [2] => 2 [3] => 3 )
$sub_min_points Array ( [0] => 700 [1] => 800 [2] => [3] => 500 )
$sub_max_points Array ( [0] => 200 [1] => 400 [2] => [3] => 300)
$stmt = $DBcon->prepare("INSERT INTO `position_grading`
(`position_id`, `grading_sub_id`,
`grading_main_id`,sub_min_points,
sub_max_points)
VALUES (?,?,?,?,?)");
$stmt->bind_param("sssss",$last_id, $d1, $d2, $sub_min_points, $sub_max_points);
I used this to fetch data from arrays and insert it to database
$sub_elements = $_POST['sub_elements'];
$outA = array();
$outB = array();
foreach($sub_elements as $value)
{
list($x, $y) = explode(":",$value);
$outA[] = $x;
$outB[] = $y;
}
foreach(array_combine($outA, $outB) AS $d1 => $d2) {
$d1;
$d2;
$sub_min_points = $sub_min_points[$d1];
$sub_max_points = $sub_max_points[$d1];
$stmt->execute();
}
when I delete these two lines it's working and send data to the database
$sub_min_points = $sub_min_points[$d1];
$sub_max_points = $sub_max_points[$d1];
I want to use foreach to fetch 4 arrays at once this is my problem.
The problem fetch 2 arrays and use $d1 as a key
I tried the solution here looping through multiple arrays and inserting into SQL
it's not working with me.
Thanks
serialize()orjson_encode()on the arrays to turn them into a string and store that