+3  A: 

If you've got two tables and there are about 60-70 rows, it's all going to be in memory extremely easily. Is it actually causing you any pain at all? I can't see how this would be a problem, unless you're either getting a vast number of hits, or you're running your database and site on a tiny, tiny machine.

Jon Skeet
An ant-sized computer for example? - mind you, bigger keyboards can be used with all those limbs.
Rudu
First of all, wow, first time in my life I see person having 215k reputation :). Secondly, what do you mean `t's all going to be in memory extremely easily`. It isn't causing any pain now, because I am testing it on local host, but some day I will launch it and there will be a lot of members (I hope) and maybe it is not very good pull out a lot of information from database every page load.
hey
@hey: The database will have it all cached if it's even the slightest bit sensible. It doesn't sound like you're pulling a *lot* of information from the database. Just imagine how much needs to be pulled out to load a single page from Stack Overflow :)
Jon Skeet
For this page I guess it is just question table and comments table. So two queries. And wait, the third query is for `related topic`. And I guess it takes the most resources. And plus I am sure SO caches a lot. :)
hey
+2  A: 

Some information could be stored in the session. Non-volatile things like user name, player/character name, etc... That's not going to change very often. But things like current score, gold/credits available, etc.. which change frequently and should be kept consistent would most likely have to be pulled from the database each time. Consider what happens if they open two browser windows and do some shopping in each. Both load up saying you've got 500 gold available and both could potentially purchase something for 499 gold at the same time.

But, it comes down to what's faster, really. Do some benchmarking and see if pulling 60-70 bits of data from the database for each hit is faster/slow than pulling a mix of database/session data.

Marc B
+2  A: 

A single query per page is actually really good - a more complicated site/application will include multiple requests. If the information isn't always required, you could include right at the beginning of every page:

$require_lookup=false;

Or true - depending on if the info needs to be loaded this time. This spares the lookup on the pags when it isn't needed (presumably some pages are outside the game - the help page for example).

Storing that data in sessions, assuming they're file based (you can get database base sessions too, which will have you right back where you started) will simply move the memory constraints from the database to the file-system. Ultimately if your application is going to become popular, you'll be separating the database server from the PHP server - maybe even using multiple PHP servers - which will mean a file based session system will no longer work.

Stick with what you've got - it'll work fine for now.

Rudu