帮助在会话/数据库中存储购物车项目
我正在使用 Kohana,但我认为这个问题通常与 PHP 有关。
我无法概念化如何做到这一点 - 我需要将物品存储在购物车中(我知道,这里是基本的东西),并且似乎无法想到存储/检索此信息的最佳方法。我可以很好地存储一些购物车物品,但无法了解如何存储购物车中的每个单独物品(我的一个想法是使用 item_1、item_2 等的键存储每个物品)。另一个想法是存储在数组中,但我不知道如何在数据库中存储数组,以及如何检索它。我知道菜鸟问题,但任何帮助将不胜感激。
I am using Kohana, but i think this question could pertain to PHP in general.
I am having trouble conceptualizing how to do this - I need to store items in a cart(I know, basic stuff here), and can't seem to think of the best way to store/retrieve this information. I can store a count of cart items just fine, but can't see how to store each individual item in the cart (one idea i had was to store each with the key of item_1, item_2 etc). Other idea was to store in an array, but i have no idea how to store an array in the database, and how to then retrieve it. Noob question, I know, but any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要将购物车及其商品存储到数据库中,请创建 3 个表:
更好的方法是将数组存储在会话中。您可以使用 PHP 内置函数来实现:
稍后阅读内容:
To store a cart and its items into a database create 3 tables:
The much better way is to store the array in a session. You can use PHP built-in functions for that:
To read the content later: