Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm working with codeigniter, now i'm doing a php loop (x100), in each loop i do a mysql query, the result is fine, 1 sec. But is it the good way to do it ? i could make a single mysql query and find the results in an array with some loops, do you think that would be better ?

Thank's

share|improve this question
9  
A single query will almost certainly be faster and more efficient than 100 individual queries –  Mark Baker Jun 14 '13 at 14:24
1  
If there's a way to combine the logic into a single query it probably would be faster because you'd have only one call out to MySQL instead of 100+, but the single query would have to be relatively efficient. It all depends on your situation. If you need help combining this into a single query please add code to your question. –  Ed Gibbs Jun 14 '13 at 14:25
 
You should never run queries in loops. –  Jessica Jun 14 '13 at 14:27
 
@jessica: never say never. –  Marc B Jun 14 '13 at 14:30
 
What kind of query are you doing? Can you provide an example? –  Matteo Manchi Jun 14 '13 at 14:30
show 1 more comment

1 Answer

no code to give a real answer. but it might be better to do the loop inside the mysql query depending on if results are reusable or multi results can be taken from mysql query

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.