动态大小二维数组
我目前正在一家网上商店工作。为此,我需要制作一个二维数组来存储移到购物车的物品。
购物车:
Cart = Session("Cart")
Items = Session("Items")
当一个项目被移动到购物车时:
Items = Items + 1
Cart(1,Items) = Items
Cart(2,Items) = rs("id")
Cart(3,Items) = Request("attr")
Cart(4,Items) = rs("name")
Cart(5,Items) = rs("price")
Cart(6,Items) = 1
最后:
Session("Cart") = Cart
Session("Items") = Items
但是我遇到了 asp 缺乏对动态大小的二维数组的适当支持的问题。或者我只是采取了错误的方式?你能帮助我吗?
I'm currently working on a webshop. For that i need to make a two dimensional array to store the items moved to the cart.
Cart:
Cart = Session("Cart")
Items = Session("Items")
And when an item is moved to the cart:
Items = Items + 1
Cart(1,Items) = Items
Cart(2,Items) = rs("id")
Cart(3,Items) = Request("attr")
Cart(4,Items) = rs("name")
Cart(5,Items) = rs("price")
Cart(6,Items) = 1
And finally:
Session("Cart") = Cart
Session("Items") = Items
But i'm having issues with the asp lack of proper support of dynamic sized two-dimensional arrays. Or am i just taking it the wrong way? Can you help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能想创建一些对象而不是使用数组。或者甚至是 结构(如果有)没有方法。
这是一个结构体的示例
,现在您可以:
或
将 Rectangle 示例与 Item 交换,您应该就可以了。
这样,每个购物车的单个实例就有多个项目,每个项目都有自己的一组属性。
You might want to create some objects instead of using arrays. Or even a structure, if it's got no methods.
Here's an expamle of a struct
so now you can:
or
Swap the Rectangle example with Item, and you should be on your way.
That way, a single instance of each Cart multiple Items that each have their own set of properties.
为与存储购物车中的商品列表的表相关的用户存储
ShoppingSessionID
不是更简单吗?这样,您只需存储Session("ShoppingSessionID")
。Would it not be simpler to store a
ShoppingSessionID
for the user that's related to a table that stores a list of items in the cart? that way all you have to store isSession("ShoppingSessionID")
.在我看来,您的问题可以通过动态调整大小的项目对象列表来解决。在这种情况下,您需要创建一个 Item 类,然后将每个新项目的新 Item 对象添加到购物车列表中。
It seems to me that your problem could be solved with a dynamically sized list of item objects. In that case you would want to create an Item class and then add to the Cart list a new Item object for each new item.