a couple of array questions...

# Thread: a couple of array questions...

1. Senior Member
Join Date
Dec 1969
Posts
1,212

## a couple of array questions...

hi all<BR><BR>I&#039;m building a lovely shopping cart, and it&#039;s all going swimmingly so far. However, I have two questions.<BR><BR>Firstly, how can I get my application to delete specific items from my shopping cart? I have an ID number for each cart item (obviously).<BR><BR>Any ideas?<BR><BR>Also, how can I total up the values from a specific "column" in my array to show the total value of items in the cart?<BR><BR>Cheers<BR><BR>Rob

2. Senior Member
Join Date
Dec 1969
Posts
1,024

## RE: a couple of array questions...

"Firstly, how can I get my application to delete specific items from my shopping cart? I have an ID number for each cart item (obviously)."<BR><BR>in vbscript you can&#039;t; you&#039;d have to go through all the elements, find the one with the correct id, and "move up" all the ones below it, effectively deleting it.<BR><BR><BR>"Also, how can I total up the values from a specific "column" in my array to show the total value of items in the cart?"<BR><BR>assuming you have a 2d array(arrTest), with id(0) & price(1) "columns"; e.g.<BR><BR>arrTest(0,0) = "1234"<BR>arrTest(1,0) = 12.99<BR><BR>arrTest(0,1) = "1235"<BR>arrTest(1,1) = 1.99<BR><BR>etc<BR><BR>valTotal = 0<BR>for i = 0 to uBound(arrTest, 2)<BR> valTotal = valTotal + arrTest(1,i)<BR>next<BR><BR><BR><BR>that help?<BR><BR>cp

3. Senior Member
Join Date
Dec 1969
Posts
1,212

## the totals thing...

... helped a lot. I&#039;m having a slow day and I couldn&#039;t get that loop right by myself for the life of me ;-) christ knows why - I was nearly there lol. just tired I guess.<BR><BR>hmmm. I might look at some 3rd party carts like Comersus for tips on possibly finding a workaround on the deleting issue.<BR><BR>Cheers Craig :-)

4. Senior Member
Join Date
Dec 1969
Posts
1,024

## if you want my advice.....

don&#039;t store the shopping cart in an array.<BR><BR>store it in a database & just hold an id in the session variable.<BR><BR>This lets you delete, update & total the products simply.<BR><BR><BR>c

5. Senior Member
Join Date
Dec 1969
Posts
1,212

## isn't that rather a waste of resources?

...not to mention being a bit nasty from a business point of view?<BR><BR>If I do that, what happens when the visitor decides to give up halfway through, having already added a bunch of items to the cart? I&#039;m left with a load of useless data on my database.<BR><BR>I prefer to go with session-maintained arrays really - that way if the visitor f*cks off with a full but unpaid-for cart, the whole shebang gets dumped when he closes his browser or his session times out.<BR><BR>Don&#039;t you think?

6. Senior Member
Join Date
Dec 1969
Posts
1,024

## RE: isn't that rather a waste of resources?

you&#039;ll actually find that an array based approach will be more resource hungry; session data will stay in memory for upto 20 minutes after the user has actually left.<BR><BR>As for "I&#039;m left with a load of useless data on my database.", the data isn&#039;t useless; you can still analyse it to see what things people are considering buying, and try to find out why they&#039;re not completing the transaction, you can also see what things people are buying together (i.e. a person that buys a particular dvd is also buying a particular ps2 game) (this lets you target your offers better).<BR><BR>What i tend to do is have a date column in my table, which is set to approx 15 mins after the user adds it to their cart, then every time the user requests a new page i&#039;ll update this column to be 15 mins after that request, if the user stops hitting your pages, you can write a little program to come along and delete all those entries older than 15mins (or put them into an analysis table).<BR><BR><BR>Never underestimate the value of the data you collect; it&#039;s the only contact between you and the potential customer.<BR><BR>cp

7. Senior Member
Join Date
Dec 1969
Posts
1,212