Is it a good idea to put a huge block of html in a session var (the html to
display the basket), and use that. Then once a product is added/removed from
the basket, requery the database and recreate the html...?
All you really need to do is write the shopping basket code once and save
it in a file then use 'include' to include the in every page you want it
on. You will need to write the shopping basket code as a function which
you, once you have included it, on the other pages you can call in the
right place you want it in the page.
I think it's also possible in php.ini to have PHP automatically append a
page onto the end of every page the web server serves so you may be able to
do it that way
Maybe I left to much to common sense..., maybe I wasn't specific enough...
Different have different shopping baskets!!!
(forgive my sarcasm, but I thought everyone knew how a shopping basket
worked!)
The problem I'm trying to overcome, is the database queries on every page
hit that pull the product info out (name, price etc.) to be shown in the
basket. I can't put this in an include. I want to create this list of
products once, then only update it when they add/remove something from the
basket (to save on database queries!). Putting a function that makes all the
database queries into an include makes no difference to putting it into the
template!
Shopping Basket
==============
Can Openers £0.79x12
Grand Pianos £1,000x4
Shipping £8,000
I don't want to recreate that on overy page for every visitor... So I could
stick it in a session variable and just pull it out each time, until they
add/remove something, which would then call a function to update the session
variable.
I just wanted to know if a session variable is a good or bad idea, and any
other ways it could be done.
And session data is less of a hit because?
You could always store the information in XML,CSV format inside a
session variable, and just parse that to produce the page.
--
Regards, CJ Llewellyn
http://www.cjllewellyn.org.uk/
http://www.north-lincolnshire.com/ (now with extra added content)
I don't know, I just assumed it's quicker than calling a database (which is
external to php's interpreter)
> You could always store the information in XML,CSV format inside a
> session variable, and just parse that to produce the page.
I just removed the only part of the site that used a session, to use a
cookie! damnit!!
Hmmm, I guess I could store it all client-side and have javascript render
it... or write out an include using the database id number. If the file
doesn't exist, create it, but then it should exist for the other calls.
These could be deleted every now and then, without worry, since should the
same visitor return, the include would be recreated....
How does that sound?
<?php
// Came from querystring!
$id = intval($id);
// If we have an id, we have a basket
// if not, we don't!
if ($id) {
if file_exist('baskets/' . $id . '.php') {
require('baskets/' . $id . '.php');
} else {
createBaketFile($id);
require('baskets/' . $id . '.php');
}
}
Diskspace isn't really an issue, but I can clear out that file every week or
so.
Anyone know which way is most efficient??
On Sat, 26 Jan 2002 11:47:19 -0500, Danny Tuppeny wrote:
<snip>
Good idea!! I'll do just that!
> > Maybe I left to much to common sense..., maybe I wasn't specific
> > enough...
> >
> > Different have different shopping baskets!!!
lmao!!! Doh!!