TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Multiple queries or not? (http://www.talkphp.com/absolute-beginners/1674-multiple-queries-not.html)

Brook 12-08-2007 05:50 PM

Multiple queries or not?
 
Hi again all (I'm sure you'll be sick of all my questions soon!),

I am a nube when it comes to PHP, but I am doing my best to learn. I have read the first few chapters of PHP and MYSQL by Larry Ulman and 'think' I have a basic grasp.

The first page I want to create is the homepage for my vbulletin powered forum/site. The page will contain a mix of static html and a bunch of queries from vbulletin.

The queries on the page will simply be calling in thread data. Latest threads posted from certain sections (eg forum sections used for articles, news, guides etc).

They will be laid out with one main story at the top, followed by two featured stories underneath. Then blocks for the latest 10 threads from each of the articles section, news section, guides section.

I'll be able to flag which story is the main or a feature, by using different thread icons.

Methods

I guess there are two ways to do this. Either have a seperate query for each bit. Eg one query for the main story, another for the two featured items, then one each for the latest 10 threads from the articles, news, guides section.

Or

Have one query for the lot and use PHP to sort and display them accordingly.

Your thoughts?

What do you think is the best way to go about it? I guess the query for each will be the easiest - but how much more difficult will it be to get PHP to sort the data how I want it? Don't forget I am a nube lol (although eager to learn :)) Any other thoughts or considerations?

Thanks in advance for your help.

bdm 12-08-2007 06:01 PM

I would use your first approach since each piece of information you're looking for is its own entity.

Village Idiot 12-08-2007 06:05 PM

To my knowledge (ive never tried the second way), you can't lump them all together. The only way to run more then one query is to use mysqli_query, which doesnt return a mysql resource (usable data).

Even if it was possible, I would recommend using one query are a time, just better code.

Brook 12-08-2007 06:21 PM

Thanks both! In that case I will focus my efforts on page caching for optimisation.

SOCK 12-08-2007 06:36 PM

It really depends on how the data is related. Using multiple queries when you can perform a single JOIN statement is inefficient, but it doesn't always work that way. Your PHP script logic should determine what data is presented where, it doesn't have to create a query at each segment.

The bottom line is your skill level and the amount of traffic you expect. Once you progress and have worked with SQL a bit you can refactor all your code to be more efficient. By that time the site may have so much traffic you'll be forced into optimizing everything.


All times are GMT. The time now is 06:09 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0