-
Array of, cookies?
I came across this little problem... see, I want to store products in my cookie like so:
('Product')(intProductID)
Code:
Response.Cookies('Product')(intProductID);
where 'product' is the field in which i locate a product, and intProductID is the value that identifies that product.
I'm sure you can all see the problem with this. Every time i store a cookie in the above statement it overrides the old Product... how can i make some kind of an array or something where it stores
'Product'(id1)(id2)(id3)
or do i actually have to do named values such as
'Product1'(id1)
'Product2'(id2)
and then simply cycle through the cookies using
'Product' + i, where i is the number by which product incriments.
Thanks ladies and gents
-
Hi Alek,
Its me again :),
This thread should be what you are looking for..
http://forums.devshed.com/showthread...574#post764574
Look at the link on the last post too.
-
Cool.. that last link looks appealing since I wont always be storing the products in an array... since the user will want to add them one by one. HMMMmm.... very appealing indeed, im just worried about CPU usage on that function, since the server is going to do all the spliting.
Also, there is no split function in Javascript... ill have to come up with something.
There would also have to be a remove function in there incase users wanted to get rid of stuff... and quantity... i would have to store quantity as well... HMmmm....
Thanks for the reply Dan, ur a life saver
-
Ok that was way too simple. I just rewrote it, heres code incase anyone is looking to do this in Jscript
Code:
function addItem(pID)
{
var strProduct;
strProduct = Request.Cookies("product")("list");
strProduct += (strProduct + ",");
Response.Cookies("product")("list") = strProduct;
}
function getProducts()
{
'This code will put the favorites into an array
var arrProductList;
var strProducts;
strProducts = Request.Cookies("product")("list");
arrProductList = strProducts.split(",");
return arrProducts;
}
-
Told you I am powered by Google :)
See why i prefer storing items in the DB in temp Table. Its might be extra resources on the server but you can be more flexible that way, and seeing which items user added to cart is valuable to justify the extra server resource use.
Make sure you check that users dont have cookies disabled or your cart will stop working.
Good luck.