Jump to content

How should I organize data for a graph from MySQL data?


jdlev

Recommended Posts

I'm looking for the most efficient way to do this:

 

1)  User enters number of days to see sales (ex. 30)

2)  Database holds day (ex. 2013-07-08) & total sales for that day.

3)  Data is sent to an array (or would a text or xml file be better to access the data?)

4)  Data is extracted from array/file/xml and inserted into a graph to display data.

 

So I suppose I could just run a for loop that looks at the database for 30 days, and returns all data, and the for loop packs the info into an array.  Another way I guess I could do it is to give the SQL query an argument that says any days for today minus thirty days, add that information to an array.

 

How would you guys go about doing it to maximize efficiency?

You would select the data with a WHERE clause such as  "WHERE datefield BETWEEN CURDATE() - INTERVAL 30 DAY AND CURDATE()".

 

How you then store the results for a graph would depend on the requirements of the software you are using to produce the graph

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.