/    Sign up×
Community /Pin to ProfileBookmark

mysql query with function within another function (and another)

Just looking for a general optimization tip here:

My problem is that I have a function that calls another function, which in turn calls another function that queries a mysql database.

The first function gives me a list of times vertically, the second adds a week of dates to the matrix, and the third queries the database with a simple, no joins query that check for an event happening on the given date and time.

It takes approximately 45 seconds to load the page. WAY too long.

Any advice on how to optimize this?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guyMar 02.2006 — Have you included breaks into the functions so that they.. well break out once they have the correct information, or do they currently continue processing the function?
Copy linkTweet thisAlerts:
@Daot_LagorilleauthorMar 02.2006 — Uhhh... I'm not sure. What do you mean by "breaks"?

Essentially, the first one is a do-while loop that prints a bunch of <tr>'s, each with a specific time in it. It keeps looping until it hits a pre-defined celing (e.g. 20:00:00).

Within that loop (in between the tr tags), I call the second function, which is anothe do-while loop that prints a bunch of td tags, one for each of 7 dates. It keeps looping until it hits it's pre-defined celing (e.g. today's date plus 7 days).

Finally, the last function is called between the td tags in the second one, and it searches the db "WHERE dte = '$thedte' and tme = '$thetme'". There is no loop in that one. After posting this thread, I eliminated the 3rd function by including the query withing the 2nd function. That cut 30% of the load time off, but it is still long (around 30 seconds). Without the query, the load time is 5 seconds.
Copy linkTweet thisAlerts:
@chazzyMar 02.2006 — refine your query!

I've built horizontal 31 day calendars using sql alone (shows a user, and what they're doing on each day).

but without seeing your functions we can't tell you what you're doing that's slowing it down.
×

Success!

Help @Daot_Lagorille 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 5.24,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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