secretip — 2010-06-12T22:15:52-04:00 — #1
Lets say I've obtained a set of over 100 items using a single mysql query and displayed them. Now, I need only the items with a certain id. Am I better off using a new mysql query or working on the existing results using PHP conditional statements?
wackyjoe — 2010-06-12T22:23:22-04:00 — #2
Why not get the items with the matching ID initially via SQL?
secretip — 2010-06-12T22:24:09-04:00 — #3
Because I need to display all the items before displaying those with a certain id.
starlion — 2010-06-12T22:25:25-04:00 — #4
If you already know what ID you need when you get the original set of data, why not do both at once?
Nothing stops you from running the id check during the display loop, and storing the results or whatever you want to do for later use.
1 loop through data is better than 2 loops.
wackyjoe — 2010-06-12T22:26:41-04:00 — #5
So you need to get all 100 of them anyway? Well in that case you just need to sort them out via PHP. No use making another mysql connection.