On 12-03-22 11:58 AM, Jay Blanchard wrote:
[snip]
Fix this code... I've come across codebases that did this specific
type of nested querying and it resulted in 10000 queries to the
database on every page. Instead, create a layered approach:

     1. Select your root elements.
     2. Loop over in PHP and create an array of parent IDs.
     3. Select the children from the database.
     4. Go to step 2.

This way you will only every perform "depth" number of queries.
[/snip]

I see what you're saying but I don't know that this reduces the number
of queries - it just handles them in a different order. How do I get to
the output that I need?

Sorry, I just realized I didn't make the optimization explicitly obvious... when I say "Select the children" I mean to select them using an IN( id1, id2, id3 ) clause instead of a query for each. This is why we build the array of parent IDs (also I wrote build an array of "child IDs", it should have read "parent IDs" and has been fixed above :).

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to