|
Posted by Bart op de grote markt on 11/22/06 08:11
listerofsmeg01@hotmail.com schreef:
> Hi,
>
> Pretty new to PHP and MySQL.
>
> I have a page on my site that displays a lot of information from
> various tables. Currently I have lots of small PHP wrapper functions
> around SQL queries to get each bit of information. This results in
> maybe 10 queries to display one page, but they are all very small and
> simple, and it keeps the PHP looking nice too as they are simple
> function calls to get each piece of info, which can be called from any
> page in my site.
>
> However, after reading up on SQL a bit, I am wondering whether I should
> be looking at just generating one large query at the start, and using
> joins etc to lump all the relevant info together. This complicates the
> PHP as this means a custom query for each page of my site depending on
> what needs to be displayed, but I am wondering if it is worth it if I
> get a fair performance gain.
>
> Can any gurus point me in the right direction? Is there a "proper" way
> to do this sort of thing?
>
> Many thanks.
Normally if you join tables, it's because they need to be joined. E.g.
if you want to display the private details of different persons from
PRIVATE_DETAILS_TABLE and all the messages that these persons have sent
from MESSAGES_TABLE, these to tables have to be joined to know what
messages belong to what person. That's logical.
Of course u can first query the PRIVATE_DETAILS_TABLE and based on that
data query the MESSAGES_TABLE with a loop, but that's not so clean and
I guess much slower since you have to query the DB again and again,
while u only need to query it once.
Greets,
Bart
Navigation:
[Reply to this message]
|