For the first time I made a website, I 'd like to ask about the website construction.

Source: Internet
Author: User
For the first time I made a website, I would like to ask my post about website construction to edit strings of different lengths (possibly empty strings) by xlrtx at 2013-03-1120:23:40 at the end of this post) save it to the database or save it as a text file? I am working on an online shopping website. every user has a shopping cart that stores the website for the first time.
This post was last edited by xlrtx at 20:23:40
Are strings of different lengths (which may be empty strings) stored in the database or saved as text files?
I am working on an online shopping website. every user has a shopping cart.

The shopping cart stores the configurations of the items they put in,

The data structure stored in this cart is an array (I saved it in json format)

However, because some users put things or not, the data length of each user's shopping cart is different.

Will the content of the shopping cart (Json data) be saved to the database or kept as a file?

If it is saved as a database, will it be stored in user. cart or cart. items?

1) if it is placed in cart. items, the system will wait until the user adds the item to Cart, then add the data to cart, and assign the user. cart_id to cart. id.

When the user cart. item is cleared, user. cart_id = 0 and the corresponding cartrow is deleted.

2) if it is saved to user. cart, each user will be allocated a long cart for storage. do you know if it will waste resources? (I do not know the database storage format ..)

3) if it is saved as a file, I will generate $ userid. json after each user registration is successful and put it in a private folder, which can only be accessed by the server and the content in it may be empty.
Database json
------ Solution --------------------
Generally, the shopping cart of a website stores session or cookie.
The performance is slightly better.
------ Solution --------------------
1. change the session mode from the default file mode to the database mode.
2. directly manipulate $ _ SESSION without json
3. to meet the requirement of "a registered user needs to be able to access the shopping cart at last login", you can add a username (user ID) field in the session table and adjust the session callback function as appropriate.

So:
If you want to use the database to save the unpaid information, the session table has been done. No More
If you want to use files to save unchecked information, it is difficult to manage multi-level directory files because of the huge access volume. the single layer is too slow. It is not a last resort.
------ Solution --------------------
Do not write a program for the purpose of the program. it is done to improve its own level.

It is wrong to consider the technical process if the business process is not clear.
Let me just talk about some mistakes in your thoughts.
1. I don't know why I want to keep the shopping cart data, just to keep it
In fact, most people have accepted the fact that they have re-logged on/dropped the shopping cart and cleared it. because of this, almost no customers complained about it.

2. "If someone has obtained the user's account password ......", The account and password are far more important than the shopping cart data, and they put the cart upside down.
If I lose my account password, I don't worry if someone else sees a condom or ink in my shopping cart. Instead, I am worried that someone else will see my shipping address and recipient's information.

3. the problem must be solved in the program.
What should be solved in the business logic is carried down by the technical logic, which is definitely not a manifestation of doing business (doing things ).

Shopping cart data is temporary data. after a shopping is completed (re-selection is complete), the data is useless-or converted to order data.
The biggest difference now is time, which is the time spent in this "completion process" and the number of views. By the way, is it useful to store data in the shopping cart for a few months?
In some cases, when technology is limited, the problem should not be complicated and can only be done. if it cannot be done, the problem should be truthfully reported to the business logic layer for solution.


If you have to turn to the best, I will give you another business logic problem:
My family and I (probably not less than 3 people) share a shopping account password, log on at multiple points, shop and ship to different locations or the same location (different orders ), how to solve the problem at the technical level? Note: Rejecting secondary logon is a business logic rather than a technical logic. I mean, how can I allow multiple logins?

Please take some time to analyze your requirements. it is most important to communicate with the business department.
------ Solution --------------------
Many Daniel.

I want to create a similar website.

Mark.

I am still reading the book PHP and MySQL Web development, and I have read it in half.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.