The first time to do the site, about the structure of the site want to ask the next

Source: Internet
Author: User
Tags php and mysql
A string of varying lengths (possibly an empty string) stored in the database or saved as a text file?
I do an online shopping site, each user will have a shopping cart

The Shopping Cart (CART) contains the items and items they put in the configuration,

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

But because some users have put things have not put, so each user's shopping cart data length is not the same

Will the contents of the shopping cart (JSON data) be saved in the database or kept as a file?

If I save it as a database, do I put it inside the User.cart or in the Cart.items?

1) If put into Cart.items, the system will wait until the user adds items to the cart, add data to the cart, and assign the user's user.cart_id to Cart.id

When the user bar Cart.item empty, then user.cart_id=0, and delete the corresponding Cartrow

2) If you save to User.cart, each user will be allocated a long cart for storage, do not know will not waste resources? (I don't know the format of saving the database.)

3) If saved as a file, I will generate a $userid.json after each user registration success, put in a private folder, only the server can access, the contents of the content may be empty.


Reply to discussion (solution)

The general website of the shopping cart is saved by the session or cookie.
Because it's a little bit better performance.

The general website of the shopping cart is saved by the session or cookie.
Because it's a little bit better performance.

Users requiring registration need to be able to access the shopping cart when they last logged in.

No registered users are written to the session.

1, the session from the default file mode to change to the database mode
2. Direct manipulation of $_session without JSON
3, in order to meet the "registered users need to be able to access the last login shopping Cart" in the session table to add a user name (user ID) field, and appropriate adjustment session callback function

So:
If you consider saving the non-checkout information in a database, the session table is already done. No more.
If you consider saving the non-checkout information with a file, the multi-tier catalog file management is difficult because of the huge number of accesses, and the single layer is too slow. Not the last resort, not the adoption

1, the session from the default file mode to change to the database mode
2. Direct manipulation of $_session without JSON
3, in order to meet the "registered users need to be able to access the last login shopping Cart" in the session table to add a user name (user ID) field, and appropriate adjustment session callback function

So:
If you consider saving the non-checkout information in a database, the session table is already done. No more.
If you consider saving a file without ...
I feel like this is a very troublesome way.
If the session is used, user a logs into the site and saves the item to Session1
After user a changed browser, login website, new Session2, but session2 inside no session1 content
Do you need to sessionid the price in the user table? Do you need to reset Sessionn to Session1 for each login?
If so, the session is set to never expire.
If someone has access to the user's account password, he knows his session, if the password is not also need to reset the session AH. This is going to be more trouble.
The session cannot expire because the registered user's cart information cannot be lost
But anonymous visitors to the session will need to be cleared after a certain time, this how to judge Ah.



JSON is a dynamic shopping cart that you want to do with Ajax.

Making a small website is 7 to 8 pages in total.

is to understand what the general solution to this problem is

The feeling session is not suitable for saving registered user information.

That's not safe.

don't write programs for the program, that's what you do to improve your level

when doing real work, it's wrong to think about the technical process without figuring out the business process
I'll just say a few mistakes in your mind
1. I don't know why I want to keep the shopping cart data, just keep it for the sake of retention
In fact, most people have accepted the fact that the re-login/drop-off shopping cart is emptied, because the customer who complained about it has almost no

2. " If someone obtains the user's account password ... ", the account password is much more important than the shopping cart data, putting the cart before the horse.
If I lose my account password, I am not worried that others will see a condom or Bimozhiyan in the shopping cart, but rather worry about people seeing my shipping address and consignee profile

3. The problem must all be solved in the program
What should be solved in the business logic, but carried down by the technical logic, is absolutely not doing business (things) performance

Shopping cart data is temporary data, complete a shopping (re-select also completed), the data is useless?? or convert to order data
Now the biggest difference is only the time, that is the "completion process" time spent and many times the problem of browsing, by the way, the shopping cart inside the data for a few months also useful?
Sometimes in the case of limited technology, the problem should not be complicated, can do, do not do the honest feedback to the business Logic layer solution


to go niu Jiao Jian, I'll give you a business logic problem:
I and my family (probably not less than 3 people) share a shopping account password, while at multi-point login, shopping and other goods to different locations or the same location (different orders), how to solve the technical level? Description: Rejecting two logons is a business-level logic rather than a technical-level logic, I mean allow multi-point login how to do?

Take the time to do your demand analysis, and communicate with the Business department the most important

don't write programs for the program, that's what you do to improve your level

when doing real work, it's wrong to think about the technical process without figuring out the business process
I'll just say a few mistakes in your mind
1. I don't know why I want to keep the shopping cart data, just keep it for the sake of retention
In fact, most people have accepted the fact that the re-login/drop-off shopping cart is emptied, because the customer who complained about it has almost no

2. " If someone gets the user's account password ... ", the account password is much more important than the shopping cart data, putting the cart before the horse ...

Add an item to the shopping cart, the user needs to select the configuration of the item, if he took the time to consider, the session expires
he will need to add items into the shopping cart, when he found that the shopping cart is gone, he will consider going to another shop?

2nd You don't understand, I mean:
in the case of the need to permanently save the shopping cart (session), if someone in a public place login is not logged out, the other person can be permanently logged in to the session, even if the password change is not used, with the user's permission, More information is available.

and the question you're giving is outrageous. Not that the technical level can solve the need to use technology to solve AH
An account is to provide services to a person,
if the use of more than one person, the account has what meaning.

1. Save the shopping cart selection to the customer, then use the database?? Many websites do this, you do not know the practice of learning peers, the customer did not save to re-election on their own responsibility, to maintain a continuous browsing session/cookies is still in, he hung more than 10 hours did not operate the cookie aging is still on the line. I often use Firefox, choose the goods for Internet Explorer online silver, or the next day to buy, the middle of the operation to save the shopping cart
2. The customer is not serious about his privacy is his problem, I most despise the net purchase does not tear off the parcel to throw away the person, the website gives the necessary warning and user agreement is sufficient. In addition, you seem to understand the cookie is not enough, the general data can be completely separated from the login information, log in and then re-stitching the general information on the line
3. The problem I give you is not really about using technology to solve it (in fact, you can solve it, you have time to think about it), but Remind you that there are many situations that will actually happen, you can not 100% from the technical level to solve, even if you solve this (account sharing is often the case, my home on this, MOM does not understand the registration, with my account under the order and I go to the money), there are more problems I can bring to you; Make things simple. To discuss with the business department, balancing the customer experience is not always the problem of the way to solve the problem

refers to the 7 floor snmr_com reply: Do not write programs for the program, it is to improve their own level of doing things

do the actual work, It's wrong to think about the technical process without figuring out the business process
I'm just going to talk about some of your thoughts.
1. I didn't know why I kept the shopping cart data, just to keep it.
In fact, most people have accepted the fact that the re-login/drop shopping cart is emptied, Because of this, the customer complained of almost no

2. " If someone gets the user's account password ... ", account ...

It's really a bit of a dead-and-dead feeling for some upstairs.
I've been writing C programs before, and I don't like wasting memory. The first time the school let us do this project, PHP has just learned less than a week.

Because I don't know how the database is stored.

So just want to ask if you put the shopping cart information into the database, each information to a certain length, each user will have shopping cart information (but some long short)
Will this waste space?

Storing it in a file is certainly not a waste of space, but is it a waste of space to store it in Vchar?

For a long while, I was doing my homework.

Database cost that's another problem.

Storage space is not important, not all SSDs, but the amount of information/traffic is important

For BS systems, the cost of a single problem is pediatrics, but BS is about thousands of concurrent connection costs, so the most important thing is to do when necessary to do more important, is that customers do not look at the product, just load the product name let him know what is enough, When he wants to see the specifics of the product, he's going to read the database. Information about the product

Database knowledge and other great God guidance, my weaknesses

Well.. Industrial Project Division. The teacher casually found a few customers, then the customer's project to us to do.

But it's a real website, and it's going to be done.

Also include documentation, user manuals, speeches, etc...

No salary. We have to pay for it. The customer also has to pay the money. Otz

A lot of Daniel.

I also want to do a similar website.

Mark's going to look later.

I'm still learning PHP and MySQL Web development, which is half of the book.

  • 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.