简体   繁体   English

比较两个PHP报表之间的差异

[英]Compare differences between two PHP Reports

I have a PHP script which currently draws out information from a MySQL database where one of the columns values are set as 'on - ie table(product) column 'on_amazon' - VALUE = 'on'. 我有一个PHP脚本,该脚本当前从MySQL数据库提取信息,在该数据库中,列值之一设置为“ on-即表(产品)列'on_amazon'-VALUE ='on'。

Table : Product
Column : on_amazon
Value : 'on' 

This report brings through all products that are currently marked as 'on' and the specified rows. 该报告将浏览所有当前标记为“ on”的产品和指定的行。

I need to be able to run this report each day and show any differences between the last report and the current one. 我需要能够每天运行此报告,并显示上一份报告与当前报告之间的任何差异。 This would reflect if there are an quantity differences for example between today and the previous day. 例如,这将反映出今天和前一天之间是否存在数量差异。

I was thinking I should create a new table, dump the data inside, compare each new day with the previous table, overwrite the previous table with the new data. 我当时想我应该创建一个新表,在其中转储数据,将每一天与上一个表进行比较,用新数据覆盖上一个表。 Rinse and repeat. 冲洗并重复。

Are there any better suggestions to this approach? 对这种方法有更好的建议吗?

Thanks, 谢谢,

Assuming you basically want to see how many products were sold today I would simply add columns to the product table, one for total products sold on a day "sold_today" and a last transaction date column "tran_date". 假设您基本上想知道今天售出了多少产品,我只需在产品表中添加一列,一列表示当天“ sold_today”售出的产品总数,最后一个交易日期列“ tran_date”。 Upon the update of the table's quantity column, for instance when 1 product gets sold, I would do something like this: 在更新表格的“数量”列时,例如,当售出1种产品时,我将执行以下操作:

update product set quantity = quantity - 1, 
    case when datediff(tran_date,curdate()) >= 1
       then sold_today = 1
       else sold_today = sold_today + 1
    end,
    tran_date = curdate()
where product_id = product_to_update;

The accuracy of the above statement (and also the option you mentioned) will be highly dependable on the time you run the statement because the data will get overwritten. 以上语句(以及您提到的选项)的准确性将在很大程度上取决于您运行该语句的时间,因为数据将被覆盖。

IMHO, a better solution would be to create a detailed transaction table specifically to store what product was sold when and then you just have to count the number of records for a specific date. 恕我直言,更好的解决方案是创建一个详细的交易表,专门存储何时销售什么产品,然后您只需要计算特定日期的记录数即可。 This would also enable you to run statistical reports for any day. 这也使您可以每天运行统计报告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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