Jump to content

Im Not Doing This Right


Kovo
 Share

Recommended Posts

Hello all,I posted the block of code Im talking about here: http://pastebin.com/m1aa54ae5This code block starts off with a mian select query that gets a list of categories for my blog.Then, for every category it gets the count of articles in that category.Then, it starts to select DISTINCT Years in each category based upon Articles that exist in those years and in that particular category.It also then gets the article count for those years.Lastly it does the same for DISTINCT Months, and count of articles in each month.My question is... This cant be right. The code block posted above works like a charm, but it is efficient code?Granted my blog wont get 1000 hits an hour, but lets say this was large scale, is there a way I can consolidate Queries? To make less connections to the DB?Thanks, and keep in mind I just recently delved into MySQL/PHP work.

Link to comment
Share on other sites

If you're worried about the database requests taking too long, you can get all of the articles at once and manually loop through them to figure out which month, year, and category they're in. That's going to increase the memory requirements for the PHP script, but will not use the database as much.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...