Author Topic: Best way to handle dataset  (Read 2828 times)

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14305
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Best way to handle dataset
« on: November 04, 2013, 09:57:52 AM »
So I have to generate a report that shows data over several years broken out by month.  Each contract in the database has data somewhere in those years, but may have records spread out randomly (like 2-3 months in one year, then 1 month in the next year).

Data:
Contract | 01/2009 | 02/ 2009 | 03/2009
ABCD      | 0            |  500        | 200


Shitty example, but in the above the database only holds records for Feb and March.  My previous code was running a query based on the month and year in my loop but that's obvious inefficient.

So my initial thought was to run the query for a single contract and dumping it into an array, putting the key of the array as the month and year... but then I have multiple values to look at.  So I was going to create a bunch of objects containing the data... but then how do I search a bunch of objects to see if one exists for the year and month I need to output?  I feel like I will end up with an array of objects.

Did that make any sense?

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14305
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: Best way to handle dataset
« Reply #1 on: November 04, 2013, 10:10:40 AM »
I'm almost wondering if it's better to just run the query and grab the first result.  Check to see if that result matches the current month and year that I need and if it doesn't keep looping.  Once the current result matches, fetch the next and continue.  That might be just as good.

hans

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3523
  • Karma: +46/-18
Re: Best way to handle dataset
« Reply #2 on: November 04, 2013, 12:09:54 PM »
What do your table(s) look like and what do you want it to look like when you're done? You could probably just done some simple group by's in a SQL statement.
This signature intentionally left blank.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14305
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: Best way to handle dataset
« Reply #3 on: November 04, 2013, 01:18:54 PM »
The main table I'm pulling from has data in rows by month.  The resulting report needs the data in columns.

Argh, I could go into more details but I have a working version of it now that I'm tweaking and it runs pretty quickly.  And I'm not using arrays or objects unless you consider the row data to be pulled out into an array which I suppose it is.

TL;DR - I got it covered.