I have a script, actually the logic for a script, to create a dynamically generated menu of the <ul> <li> type from a database table which consists of links, IDs, and parentIDs. There are two ways I know how to do this, but I am wondering which one is more efficient:
1) I could pull all the entries out of the database with one query, run through a loop that puts them in 2 or 3 separate arrays, and then run a couple of loops on the arrays to spit out my menu
OR
2) Run a single loop which contains a mysql query (i.e. run many queries) which will build the menu
I know the second way uses less lines of code, but how efficient is making many mysql queries vs building the menu through using a few different array functions and loops in php?
I know this is a general question and if it is a ridiculous “it makes no difference answer” then somebody can just say that too. Thanks