473,767 Members | 2,152 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Shopping Basket / Sessions

Hi all,

I need to implement a simplistic shopping basket/checkout thingy...

I kinda threw something together, but its not keeping more than one item in
the session...

I'm basically loading the page, checking to see if there's an "addToBaske t"
value in the querystring, if there is then I grab the product code (also in
the querystring) - now - here's where it seems to be going wrong...

I figured to keep a multitude of product codes in the session variable I'll
need to store an array...so, I first check to see if the
session("Basket Items") is "" / nothing - if so, I dim in an array, if not
then I set a variable to equal the session("Basket Items")...

I then get the UBound of the array, add 1 to it, and do a ReDim Preserve,
and add the product code from the querstring to the array at that
position...

Everytime the page loads I only ever have one item in it..

Anyone got any ideas? I must be doing something stupid here...

Any info appreciated..

Regards

Rob
Jun 8 '06 #1
4 2448
Rob Meade wrote:
Hi all,

I need to implement a simplistic shopping basket/checkout thingy...

I kinda threw something together, but its not keeping more than one
item in the session...

I'm basically loading the page, checking to see if there's an
"addToBaske t" value in the querystring, if there is then I grab the
product code (also in the querystring) - now - here's where it seems
to be going wrong...

I figured to keep a multitude of product codes in the session
variable I'll need to store an array...so, I first check to see if the
session("Basket Items") is "" / nothing - if so, I dim in an array, if
not then I set a variable to equal the session("Basket Items")...

I then get the UBound of the array, add 1 to it, and do a ReDim
Preserve, and add the product code from the querstring to the array
at that position...

Everytime the page loads I only ever have one item in it..

Anyone got any ideas? I must be doing something stupid here...

Any info appreciated..

Regards

How was the array initially Dim'ed? Only dynamic arrays, ie those dim'ed
with no dimensions in the parentheses will preserve data in redims.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jun 8 '06 #2
"Bob Barrows [MVP]" wrote ...
How was the array initially Dim'ed? Only dynamic arrays, ie those dim'ed
with no dimensions in the parentheses will preserve data in redims.


Hi Bob,

Only seems like yesterday you were solving my problems - turns out it was a
couple of days ago :oD

Ok - I've made a little progress since posting, although not a lot....I
currently seem to lose the first item added, although the array size looks
ok...

Here's the code:

If Request.QuerySt ring("action") = "addToBaske t" Then

Dim arrBasket

arrBasket = Session("Basket Items")

BasketItems = UBound(arrBaske t) ' this line typically fails on the first
load of the page if there is nothing in the basket already, ie no array in
the session variable - but no error is displayed

If BasketItems = "" Then

BasketItems = 1
ReDim arrBasket(1) ' size it up as we need to add an item

Else

ReDim Preserve arrBasket(Baske tItems+1) ' size it up again based on what
it is plus 1
Response.Write UBound(arrBaske t)

End If

arrBasket(Baske tItems-1) = Request.QuerySt ring("product") ' need to deduct
one now so that hte first item goes into arrBasket(0) etc

Session("Basket Items") = arrBasket

End If
Jun 8 '06 #3
<%

If Request.QuerySt ring("action") = "addToBaske t" Then

Dim arrBasket

arrBasket = Session("Basket Items")

BasketItems = UBound(arrBaske t)

If BasketItems = "" Then

BasketItems = 0
ReDim arrBasket(Baske tItems+1)

Else

ReDim Preserve arrBasket(Baske tItems+1)
Response.Write UBound(arrBaske t)

End If

arrBasket(Baske tItems) = Request.QuerySt ring("product")

Session("Basket Items") = arrBasket

End If

%>

I now get the items added correctly to the array...

Example here - there's 3 links on the page in the main area, each has a
different product code (for testing purposes) - the "basket" is displayed at
the bottom of the main content area for now (again, for testing)....see ms ok
right?

http://82.46.23.70/parasolit/trainin...product=a2km01

Rob
Jun 8 '06 #4

"Rob Meade" <te************ *********@edaem .bbor> wrote in message
news:Yj******** *********@text. news.blueyonder .co.uk...
<%

If Request.QuerySt ring("action") = "addToBaske t" Then

Dim arrBasket

arrBasket = Session("Basket Items")

BasketItems = UBound(arrBaske t)

If BasketItems = "" Then

BasketItems = 0
ReDim arrBasket(Baske tItems+1)

Else

ReDim Preserve arrBasket(Baske tItems+1)
Response.Write UBound(arrBaske t)

End If

arrBasket(Baske tItems) = Request.QuerySt ring("product")

Session("Basket Items") = arrBasket

End If

%>

I now get the items added correctly to the array...

Example here - there's 3 links on the page in the main area, each has a
different product code (for testing purposes) - the "basket" is displayed at the bottom of the main content area for now (again, for testing)....see ms ok right?

http://82.46.23.70/parasolit/trainin...product=a2km01
Rob


Rob,

Your use of variable names is confusing. The variable BasketItems is a
count of items in the basket but the session variable key for the array is
also called BasketItems.

Also you are making the array one element bigger but then place the product
in the element previous to the one added, is this intentional?

In cases such as this I tend to ignore the 0 element of an array and treat
it as one based, things tend to make more sense that way.

Try this refactoring:-

<%

If Request.QuerySt ring("action") = "addToBaske t" Then

Dim arrBasket
Dim lItemCount

arrBasket = Session("Basket Items")

If IsEmpty(arrBask et) Then ReDim arrBasket(0)

lItemCount = UBound(arrBaske t) + 1

Redim Preserve arrBasket(lItem Count)

arrBasket(lItem Count) = Request.QuerySt ring("product")

Session("Basket Items") = arrBasket

End If

%>

Just remember that when enumerating the array use For i = 1 To
UBound(arrBaske t)

One advantage is if there are no products in the array then the array has
UBound = 0.

Anthony.
Jun 9 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2274
by: Fnark! | last post by:
I am creating a shopping cart using PHP Version 4.1.2. I am creating and registering a cart object in a session. The cart object contains an array of arrays called $order whose elements are a collection of $orderline associative arrays which, in turn, hold the global POST values key 'order_code' and value 'qty' as passed in from another page. My problem is (shown by using print_r to print out the contents of the arrays) each time I...
0
1672
by: Ian N | last post by:
Hi, I've been working on a PHP Shopping Basket and have hit a problem. I wanted update the DB with the contents of the Array which forms the basket. This isn't a problem, however i'm unsure how i use Relational Tables in MySQL. I have a table called Orders, which stores the CustomersID and also has an OrderID (this is an autoincrement integer)
4
1823
by: Richard Pain | last post by:
OK - I have a shopping basket with data in a database. Once the person has successfully completed their order I want to be able to send them an email with the products ordered roughly in the following format: Product Price Quantity prod1 £6.99 1 prod2 £5.99 2 Postage ...
3
1873
by: Samuel Shulman | last post by:
Hi I need to implement a shopping basket for my e-commerce website Scenarios are as follows 1. Website to offer shopping basket for all visitors including those who didn't log 2. Website to offer shopping basket ONLY to those that are logged
2
1446
by: Samuel Shulman | last post by:
I want to allow customer to 'Add to Basket' even if they are not logged. Once they log the content of the basket will be saved for the future Next time they may add other items to the basket before they log and then they may log What is expected at that point? Merge the content of the baskets delete the old one or else
11
2001
Fary4u
by: Fary4u | last post by:
Hi i've design the ASP shopping with MS Access database it's working fine there is no problem in LOCALHOST when i upload into the Host Server it's working fine but when u add product into basket it's bring automatically 1 extra product some time 2 or some time 3 i've not made a file called GLOBAL.asa for generate session but if some body add item into the basket it takes OrderID & using Session .
0
1812
by: Shanthini Ganesh | last post by:
hi all. now i m creating shopping cart. i would like to make when the user click the add to basket button, item added visually shown to user. i found one script for this in net.. but i couldnt pass dynamic productid to that addtobasket javascript function. this is my function.. function addToBasket(productId) { if(!shopping_cart_div)shopping_cart_div = document.getElementById('shopping_cart'); if(!flyingDiv){ flyingDiv =...
0
1029
by: jasone | last post by:
Hi all and happy new year! so here's my little problem, im developing a shopping cart for a florist. there will be a traditional shopping cart where the user adds item to basket and so on. i am struggling getting my head round an additional features which will allow the user to create their own bouquet. this will involved a 'flowers_details' tables where the user can select what flowers they want in their basket. when they finish choosing...
3
1173
by: jasone | last post by:
Hi all and happy new year! so here's my little problem, im developing a shopping cart for a florist. there will be a traditional shopping cart where the user adds item to basket and so on. i am struggling getting my head round an additional features which will allow the user to create their own bouquet. this will involved a 'flowers_details' tables where the user can select what flowers they want in their basket. when they finish choosing...
0
9571
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9405
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10013
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9841
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6655
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5280
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3930
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3533
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2807
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.