Domanda

Im pulling information from an API, the information is presented as an array of objects, i loop through and pull the information i need, sometimes it involves pulling from several objects for example i might want to pull the username from the users object and then from the activity object how many hours that user has worked.

Ive coded with php and i can display the information but i want to be able to drill and sort the information so im thinking creating a Mysql temp table, insert all the values and sort them whatever way i like.

Is that the best choice, this is a clockin system so i will be the main one running reports so speed isnt really an issue, some of these queries are simple and some a little more complex, but were only talking about 100-200 records a day and for the most part ill be only running the queries on 1-2 months of data only a few thousand records.

My main reason for using SQL is to easily sort by date, from, between, after type thing. Also whats the best way to handle deleting the temp table, i presume deleting it every few day will suffice.

Also one thing im unsure on, lets say most of my reports will be run on the last 60 days, by default i should basically run the report on the last 60 days and when someone filters it within those 60 days it will show me the relevant data from the temp table and basically re-use the information over and over. I could then put in an IF statement that if the from date exceeds 60 days i would need to pull all the information again from the api and do another new temp table or should i just load all the data into mySQL for all time and filter as i want using the same table with 1 large initially query?

FWIW retrieving the information from the api is the slowest part seems to be a few secs delay so working directly with the info from SQL should be smoother.

Im new to SQL so im not sure of what the best solution is, i could be way off on the approach im taking so im basically looking for the most efficent option that minimizes coding and is newbie friendly. Im coding in php btw

È stato utile?

Soluzione

SQL is usually a nice language to create reports in. Can you always pull all the data you need from the API, i.e. if you run a report for the last two months, does the API supply all the historic information? If not, you'll have to retrieve data periodically and store it in a database. On the other hand, if you have all the data you need, PHP can filter and sort data fine, too, it'll be a lot easier if you leave out the database part.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top