Jump to content

Resource Management


Fehrant

Recommended Posts

I am building a forum, and I already got the basics working (registering, signing in, showing and posting in both threads and posts, section->forums->threads->posts architecture displaying properly). However, right now I'm starting to struggle over the details. Particularly this post will be about the navigation links (in this forum, the navigation bar would be: PHP Freaks Forums > PHP and MySQL > PHP Help -> Title of thread).

 

Each of the pages that display any information from the db, use 2 queries tops, and I'd like to leave it at that to minimize hammering the db with multiple queries from multiple users. However, notice how the navigation bar is processed before the actual listing of either threads or posts. That would merit another query in itself, but I want to avoid it, so I thought of two possible solutions. I want to know however if the trouble would be worth it.

 

1) Creating a class to create all the HTML, that will be able to inject variables' content into the HTML thus created. This would enable me to first do all the PHP processing, and afterwards simply pouring the content conveniently as I see fit.

 

2) Storing all the threads/posts in an array beforehand, and then simply looping the array.

 

I hope I was clear enough. Any questions, just ask.

Link to comment
Share on other sites

Well, you've just encountered "programmer's choice". Decide which way you want to go, and get going with it. If you are comfortable with OOP, design a class to handle forum objects. Since I'm very comfortable with arrays, I would certainly choose that route out of convenience. In the end, you're going to create arrays anyways... whether you use them directly or within a class is the only question.

 

PhREEEk

Link to comment
Share on other sites

PhREEEk, thanks for the reply. It's kind of embarrassing now that put it that way ("programmer's choice"). I'm partly glad though that's the case. Since I'm a newbie, the solutions to the problems I find could be due to lack of knowledge rather than legitimate ways, so I was rather skeptical. You're dead-on on pointing out I'll be using arrays anyway.

 

I am not very comfortable with OOP, I suppose I'll end up doing arrays. 

Link to comment
Share on other sites

If you're good with arrays, you'll be fine as long as your array structure is well thought out. If you're not good with arrays, you're going to be... very soon! hehe  Which is not a bad thing at all... = ^)

 

If your array structure is built for it, you could use a template system for sending the page to the browser, but that's a whole 'nother subject/endeavor.

 

Well, guess you're going be kind of 'busy' with arrays for a few days! Just walk slow and drink lots of water! You'll be fine! Best of luck... we're here when you need to cry 'Uncle!'  = D

 

PhREEEk

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.