Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Shopping Basket on Every page???

0 views
Skip to first unread message

Danny Tuppeny

unread,
Jan 26, 2002, 8:41:02 AM1/26/02
to
A shopping basket is going to be shown on every page of my site. I guess a
some database queries to get the product name, price, quantity on every page
is needless. Any ideas on the best way?

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...?


Joe

unread,
Jan 26, 2002, 10:48:23 AM1/26/02
to
Danny Tuppeny wrote:

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

Danny Tuppeny

unread,
Jan 26, 2002, 11:47:19 AM1/26/02
to
> >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.
>
>
> Cant you write it not as a function. Just as code and use
> <? include ?> and whatever you have is then shown at that point on
> every page? rather than an include and then a function?

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.


CJ Llewellyn

unread,
Jan 26, 2002, 2:31:00 PM1/26/02
to
On Sat, 26 Jan 2002 16:47:19 -0000, "Danny Tuppeny"
<dannytuppeny-@-ntlworld-.-com> typed with two fingers:
-snip-

>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

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)

Danny Tuppeny

unread,
Jan 26, 2002, 2:57:09 PM1/26/02
to
> And session data is less of a hit because?

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??


Ray Taylor

unread,
Jan 26, 2002, 3:05:20 PM1/26/02
to
Store the cart is session variables. If you do that, you only need to
hit the db when an item is added. you can include the cart contents on
every page with a simple check of the session variablse.
Updating the cart by changing
quantities or whatever won't need to query the db, just manipulate
session variables. When a user goes to check out, you can perform one
more query of the db to make sure that none of the item proces have been
tampered with.

> Different have different shopping baskets!!!
Different "what?" have different shopping baskets?

On Sat, 26 Jan 2002 11:47:19 -0500, Danny Tuppeny wrote:
<snip>

Danny Tuppeny

unread,
Jan 26, 2002, 3:12:30 PM1/26/02
to
> Store the cart is session variables. If you do that, you only need to
> hit the db when an item is added. you can include the cart contents on
> every page with a simple check of the session variablse.
> Updating the cart by changing
> quantities or whatever won't need to query the db, just manipulate
> session variables. When a user goes to check out, you can perform one
> more query of the db to make sure that none of the item proces have been
> tampered with.

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!!


0 new messages