I have several hundred thousand records that will add a monthly db row if new data exists. I plan on working this info into a chart, but I see no reason to add values that contain 0. For 350,000 records, doing it this way reduces new monthly records to about 8,500, vs 350,000 - a huge performance improvement if this is possible.
I figured that an array will help solve this.
For example, looping over the data in SQL, will return something like:
while ($r = $result->fetch_assoc()){
$id[] = $r["id"];
$revenue[] = $r["revenue"]; // Revenue for example
$date[] = $r["date"]; // 2016-07
}
So, the result will have the dates, id's and revenue stored as an array. Using ksort() will sort the dates, however is there a plausible way to add missing dates (that have 0 values)?
Sorry for not being more clear, this is the best way I could describe this. I thank you for your help. DB storage is limited and expensive, and this is a critical step on the long term project.