shopping cart - How to store information in a field in Database? -


ok building simple shopping cart website , have researched question, have been unsuccessful @ finding answer.

i have these tables far:

item ------ id categoryid brandid name price    categories ----------- id name    brands ------- id name    shopping carts -------------- id userid itemids itemprices itemquantities 

based on other answers have found seems correct way, except not sure shopping carts table. considering storing information in table so:

id: 1 userid: 1 itemids: 1;2;3;5 itemprices: 40;50;60;70 itemquantities: 1;2;3;4 

is correct way of tackling or there better way? (i thinking of using explode() function in php separating data when retrieving it.)

ideally, want store shopping cart info either in cookies or in sessions. if want store each shopping cart in db, use following implementation.

essentially, 1 shopping cart can have multiple items, each item having price , quantity associated it.

for storing carts per user, use schema:

shopping carts

cartid (primary key)
sessionid (unique id identifying user session in cart created)
purchased (boolean true/false store whether cart purchased or discarded)

shopping cart items

id (primary key)
cartid (unique id identifying user cart)
userid: (use if know user logged in while adding items cart)
itemid: unique identifier item in cart.
itemquantity: quantity of item ordered.
itemprice: (optional - use if item price customizable, or pull item table)

with above schema, if user adds 2 items cart, lets

  • item x (quantity= 2pcs, itemid = 1001) &
  • item y(quantity= 1pc, itemid = 1002).

your records in table like:

id: 1
sessionid: abc1
itemid: 1001
itemquantity: 2

id: 2
sessionid: abc1
itemid: 1002
itemquantity: 1

now, when want fetch order shopping cart - query based on sessionid in use when user creating cart.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -