Reputation: 3137
I am inserting dynamic records
var sql = "INSERT INTO Test (name, email, n) VALUES ?";
var values = [
['test', '[email protected]', 1],
['test', '[email protected]', 2],
['mark', '[email protected]', 3],
['pete', '[email protected]', 4]
];
conn.query(sql, [values], function(err) {
if (err) throw err;
conn.end();
});
here is example which is working fine
Now my data is here
var arr = category_ids.split(",");
for (var i = 0; i < arr.length; i++) {
}
How to make dynamic array of values in for loop
Thanks
Upvotes: 1
Views: 721
Reputation: 10384
You just need an array of arrays, like what values
is in the example you provided.
var arr = category_ids.split(",");
var values = [ arr ];
or simply
var value = [ category_ids.split(",") ];
Upvotes: 2