/    Sign up×
Community /Pin to ProfileBookmark

Efficiency of PHP vs MySQL Operations

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

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@chazzyDec 14.2006 — Run 1 query. Much more efficient, due to network constraints typically.
Copy linkTweet thisAlerts:
@aj_nscauthorDec 14.2006 — Thanks very much for really quick answer
×

Success!

Help @aj_nsc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...