[thelist] php/mysql speed

John Corry webshot at members.evolt.org
Mon Apr 8 14:17:01 CDT 2002


I was working on an architecture for a site we're building and came up with
a question:

My site will have its' nav generated per page based on the contents of a
MySQL db. The nav will be built from elements retrieved from a query
something like:
$nav_query = SELECT prodID, prodName, prodCategory, prodAvail from products
. 'products' is a table with about 100 items in it. So...I know the easy way
to do it...just run the query and build the nav on every page. But is that
the best way? It seems like a lot of unnecessary queries to the db.

I don't have a lot of experience with sessions, but I was thinking maybe I
could do something like:
session_start();
if (!$nav){
session_register('nav');
$nav = mysql_query($query);
That way, I have the result set that I need to build the nav available on
every page, right?

My other idea was to let the product update script (where prodName,
prodCategory, etc get updated) build a static navigation file and then just
include that file. I don't know what's slower, a query to the db or a disk
access to include a file.

Is there some commonly accepted 'best practice' for the kind of
functionality I'm working on?

thanks,
John




More information about the thelist mailing list