Hi, when a user logs into my site a session variable is created which holds certain data about the user such as username, firstname, lastname, age, address, sex, email, score, place However most of this data is only used on two pages (although they are probably the two most used pages) My Question is... Should i carry all this data around in the session variable or should i carry just the $username and then query the database each time i need the rest of the data for each page. Which would be a better method 1 - carry all the data around in the session variable 2 - carry just the username and query the database each time the page loads thanks for your help
I think you should just go for the session... It doesn't takes up resource, querying the mysql database does.
Ok, thanks guys, but one reason that i would go with the second is... If the users score changed while they were logged in, and they then clicked into their account to check their score... the score that was outputted in the session variable would still be there instead of the most up to date score. If i queried the database each time, the latest score would be pulled from the database... do you get me... THANKS AGAIN GUYS
Session data is stored on the server and constantly accessed, not to mention the disk space, so of course it uses server resources. Having said that, there is little data so storing it in a session would be better than querying the DB.