PDA

View Full Version : Query In a Loop


Logikos
08-18-2004, 06:24 PM
Can anyone explain to me what a query in a loop is? I've seen some people stat that, 'oh that query is in a loop' and its talked as its bad. So here my noob question for the day lol What is a query in a loop and how can you dectect it?

Zachery
08-18-2004, 06:26 PM
Can anyone explain to me what a query in a loop is? I've seen some people stat that, 'oh that query is in a loop' and its talked as its bad. So here my noob question for the day lol What is a query in a loop and how can you dectect it?
As far as i understand, theres a loop, like a foreach i think, so lets say it has to be run 15 times, then your query will be ran each time so 15.

At least as i understand it, thats bad :D

Modin
08-19-2004, 03:21 AM
it's very bad because then the number of queries (which is normally the bottle neck on a site) is bound by that loop. Which say if it looped 100 times, then you'd get 100 queries per visit which is way too many.

It's always more efficient to grab more than you need and cache it instead of having a query in a loop.