Jump to content
Larry Ullman's Book Forums

Recommended Posts

I love the new book its well written. I found that if you have a website with buyers and sellers and not just an individual seller the carts database is not suffice. I think that in this case it would be best to create a cart and a cart_content database like this to make it easier to sort out members shopping carts with some simple relational queiries as apposed to some PHP logic.

 

CREATE TABLE cart (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
buyer_id INT UNSIGNED NOT NULL,
seller_id INT UNSIGNED NOT NULL,
date_created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
date_updated DATETIME DEFAULT NULL,
PRIMARY KEY (id),
INDEX fk_cart_user_buyer_idx (buyer_id ASC),
INDEX fk_cart_user_seller_idx (seller_id ASC)
)ENGINE=InnoDB;

CREATE TABLE cart_content (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
cart_id INT UNSIGNED NOT NULL,
item_id INT UNSIGNED NOT NULL,
price INT UNSIGNED NOT NULL,
quantity INT UNSIGNED NOT NULL DEFAULT 1,
date_created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
date_updated DATETIME DEFAULT NULL,
PRIMARY KEY (id),
INDEX fk_cart_content_cart_idx (cart_id ASC),
INDEX fk_cart_content_item_idx (item_id ASC)
)ENGINE=InnoDB;

 

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...