Hey all, I am trying to do a couple of loops... the code I have does what it needs, but it is taking an extremely long time to go through about 5000+ rows of data and doesn't always make it as it times out at around 5 min. Just wondering if there is any way to improve upon this.
I basically have a loop that finds a list of names/ids in one table.. then what I am trying to do is match up data with those found ids and do some sums and avgs and other math operations with the numbers. The problem is that I have to have them between date ranges.. eg finding the sum of some number between Jan 03 and Jan 04 for example. Thats just one, but gives the idea.
So to do this, I am trying to loop through a created timestamp to match up with timestamps that the data already has. This takes a while since I loop through the first list of names, then inside that is a loop that goes through each year from 2003 up to 2007, then inside that is a loop that goes through each month in those years.. so I end up running a lot of checks and sql inserts/updates. Here is the little bit of code from the timestamp loop on down.
//Loop for names is up here
//Takes the years up to 2007
for($j = 3; $j < 8; $j++) {
$year = "200".$j;
//Builds the month for each year
for($k = 1; $k < 13; $k++) {
if ($k < 10)
$k = "0".$k;
$my_timestamp= $year.$k."01000000";
//Bundle of sql calls that compare against that timestamp to see if the data fits the criteria.
}
}
is there a way to be able to compare specific dates like this, without having to loop through each specific date or speed this up somehow?π