'Generate sales report using MySql and Php

I m looking for advices in report generating per client, per product, per salesman, in a given period, using mysql and php. I m currently working on an application with sales and i was wondering what is the best way to structure this function. I m planning on hosting in a shared hosting server, so i m worried about efficiency. So here are the two ways i m looking things:

1- add entries of sales then once a user specifies a period of the sales report, executing a mysql query that will sum up everything then feed it to the php to arrange it a send response back

2- fetch all entries then calculate sums and everything in php

3- on every sales, add the totals on a report table for each day, then another table for each client, then for each product then for each salesman. And once a user requires a report, fetch the totals in each table and sum up the totals (the problem here is if a sale has been edited or deleted, i have to re-adjust the totals for all tables)

I m looking for suggestions for the best way to do this, also all the data are on the same table and segregated by user_id so for example if there are 1000 users with 1000 sales, the table sales will have 1000000 rows with corresponding user_id.

Thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source