简体   繁体   中英

How do I store order history in a database using php?

I have a site where users can place an order. The order goes through various stages before it is ready for delivery. I want to be able to log anytime anything happens relating to an order.

Here's an example of what I would like for it to look:

Order initiated by Customer 客户发起的订单
Order sent to Manager for approval 订单已发送给经理以供批准
Order approved by Manager 经理批准的订单
The order was edited by the user: 订单由用户编辑:
City: 'Los Angeles' to 'San Diego'
The order was edited by the admin: 订单由管理员编辑:
Email: 'gearge@gmail.com' to 'george@gmail.com'
Order ready for Delivery 订单已准备好交付

What is the best approach for me to store this type of order history? I have created a table in the DB called history where I would like to store the history as it pertains to each order. My columns are history_id(primary), order_id(foreign), date added(timestamp), and history_message(varchar).

Ideally I would like to create numbered codes for each step in the ordering process, such as an order approval, order edit, or order delivery and then just assign the number for that row instead of the actual history message, which is more characters. I feel that this way I won't overstuff my DB. The problem with this approach is that I would like to keep a log of the actual data that was changed(as you can see in the edits by the user and admin in the example) and I'm not sure how I can accomplish that without saving the complete history message for each row.

What is the best way to store order history in a database for my situation?

You can use trigger to update a child table keeping track of each order status.

Basically using insert trigger or do manual insert after update in order status by insert query you can copy required data from orders table to a new table we can call trackorders. tracking table will keep track of all changes and record with current status will be in main table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM