Hi,
so you basically want differently themed pages whenever a user go to a new page and when he comes to an already visited page you want retain the previously shown theme.
fine analyse the following suggestions and decide how much you can take from it,
first create the cache table with following structure to cache some query results, theme selection preference etc..
CREATE TABLE cache(session_id, cache_data);
I will write an algorithm kind of solution with which you can build the program suitable to your application,
STEP 1: retrieve all available templates from your DB and form an array named say arrTemplate
STEP 2: choose a template randomly from the array and store the chosen template id in a variable say intTemplateID
STEP 3: display the page with all the details and with the template we just chosen
STEP 4: now we need to find a way to get a unique page id for the pages user visits so that we need to retain the same theme we have shown before
STEP4-SUB-STEP 1: best way of finding unique page id is to use the REQUEST_URI of $_SERVER
STEP4-SUB-STEP 2: so create an array variable named say arrTemplatePref and have REQUEST_URI as index and intTemplateID as value to create unique representation for the view user is in
STEP 5: now almost after showing the page do the last bit of processing.
STEP5-SUB-STEP 1: create an array named say arrCacheData
STEP5-SUB-STEP 2: store the arrTemplate in arrCacheData
STEP5-SUB-STEP 3: store the arrTemplatePref in sub array of arrCacheData, remember this has to be in sub array because we may need to push some more list of user views into this.
so finally this arrCacheData might look like this
arrCacheData => Array(
'TEMPLATE_INFO' => Array(1, 2, 3, 4, 5, 6),
'USER_VIEWS' => Array(
'view.php?limit=20&limitstart=50&contentid=23434' => 3,
'view.php?limit=20&limitstart=70&contentid=23434' => 1
)
)
STEP 6: this is time to store the arrCacheData into the table 'cache' we created with 'session_id' as hook. you can serialize the information before storing.
Final Implementation: At each page loads, query the cache table to check whether there is any cached data available. if so loads it in an array. At STEP 2, check the cache array before firing the query because remember we store the information in the cache table. At STEP 3, before choosing the template randomly, check the cache array USER_VIEWS sub array using the REQUEST_URI to check whether the user has already visiting the page or not and if so you can retreive the template ID and set that template as current template. thats it we have got a complete cycle of using the cache to storing the cache.
I'm not sure how cleary I have defined my solution(today is my second day at PHPFreaks so not sure of forum rules) but I'm sure by this you can acheive what you are trying to do.