/    Sign up×
Community /Pin to ProfileBookmark

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.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 10.2014 — 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:
<i>
</i>INSERT INTO table_name (
col_1,
col_2,
col_3
)
VALUES
('row1_1', 'row1_2', 'row1_3'),
('row2_1', 'row2_2', 'row2_3'),
('row3_1', 'row3_2', 'row3_3')
;
×

Success!

Help @pooja1110 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...