I hope someone is able to help me with the problem I'm facing for hours already. I'm trying to built a MySQL INSERT from two arrays. One array ($bms) holds 6 values and the second one holds 3 values (I want to use the array with 3 values inside the INSERT query where I'm using the placeholder group right now). Each value of the (group array) needs to be used 2 times. I hope you understand with my example below:
The 2 arrays – always include 6 respectively 3 values:
Array ( [0] => 8 [1] => 3 [2] => 4 [3] => 121 [4] => 13 [5] => 154 ) // $bms
Array ( [0] => 266 [1] => 267 [2] => 268 ) // group
The query with foreach loops:
$query = "INSERT INTO userlinks (linkpool_id, group, userid) VALUES ";
foreach($bms as $bm) {
$query .= "('".$bm."', group, '".$userid."'),";
}
echo $query;
The output so far:
INSERT INTO userlinks (linkpool_id, group, userid) VALUES ('8', group, '19'),('3', group, '19'),('4', group, '19'),('121', group, '19'),('13', group, '19'),('154', group, '19')
WHAT I'M TRYING TO ACHIEVE:
INSERT INTO userlinks (linkpool_id, group, userid) VALUES ('8', '266', '19'),('3', '266', '19'),('4', '267', '19'),('121', '267', '19'),('13', '268', '19'),('154', '268', '19')
I really appreciate your help and invested time – awesome community!
$bmsneeds to be associated with the first value of$group, the 3rd and 4th of$bmswith the second of$groupetc ... So each value ofgroupwill be used twice.