Reputation: 1195
I have a list with a lot of (500+) codes and I want to insert it into database.
For example: User given codes to textarea and codes are seperated by new line (\n
). In PHP it is $_POST['codes']
. Of course I can just use explode()
function and insert all codes in loop, but I'm thinking it's not a good idea with 500 repeatitions.
So, how can I do this the most optimal?
Upvotes: 1
Views: 180
Reputation: 1427
Depending on the size of your data, you could make it all into a single query if you are worried about number of separate inserts:
mysql_query("INSERT INTO mytable(`People`, `Places`, `Ideas`, `things`)
VALUES ('40', '15', '0', '0'),
('0', '5', '10', '0'),
('10', '0', '11', '12')");
(example from: https://stackoverflow.com/a/10286687/486780)
Upvotes: 2