iam having an array of items like
[item1,itmem2,item3];
i have to insert these items at a particular userId:
final results look like this
UserId ItemId
2 || item1
2 || item2
2 || item3
currently iam looping through the array in php code and inserting each item one by one eg
foreach($items as $item)
{
insert into items (UserId,ItemId) value (2,$item);
}
is it possible i can insert all entries in single query.
Yes, your query could look like this:
INSERT INTO items (UserId,ItemId)
VALUES
(2, 'item1'),
(2, 'item2'),
(2, 'item3');
You can construct that string in PHP.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With