HOw to use foreach for MYSQL Query
Hey I have a php array adn for each value of array I want to run a query and get the result.
How I can use foreach here pls guide with some example.
Well, the first thing I'd do is try to figure out how to do it all in one query if possible, as doing a separate query N number of times in a loop can be resource-intensive. For instance, you could build a single insert query from your array of data, since you can use this SQL format:
INSERT INTO table_name (
('row1_1', 'row1_2', 'row1_3'),
('row2_1', 'row2_2', 'row2_3'),
('row3_1', 'row3_2', 'row3_3')
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
How to Ask Questions the Smart Way
(not affiliated with this site, but well worth reading)
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread