I now have a working version that uses only two mysql queries instead of 1000! Let me know if you think this is a better method of implementation (also, how can I test the speed of it, simulate users?)
//set start year and end year
$startDate = -3000;
$endDate = 2000;
//select historical world events that appear on front page
$select = "SELECT title, eid, year FROM events_sec WHERE isMajor = 1 ORDER BY year";
//store results
$eventResults = mysql_query($select, $db);
//see if there are any results
$rows = mysql_num_rows($eventResults);
//put results in an array, eith Event Id as KEY
//event year and title are stored as array within array
for ($i=0; $i < mysql_num_rows($eventResults); $i++)
{
$eventArray[mysql_result($eventResults, $i, "eid")]=array(year => mysql_result($eventResults, $i, 'year'), title => mysql_result($eventResults, $i, 'title'));
}
//select historical biblical events that appear on front page
$select2 = "SELECT title, eid, year FROM events WHERE isMajor = 1 ORDER BY year";
//store results
$eventResults2 = mysql_query($select2, $db);
//see if there were any results
$rows2 = mysql_num_rows($eventResults2);
//put results in an array, eith Event Id as KEY
//event year and title are stored as array within array
for ($i=0; $i < mysql_num_rows($eventResults2); $i++)
{
$eventArray2[mysql_result($eventResults2, $i, "eid")]=array(year => mysql_result($eventResults2, $i, 'year'), title => mysql_result($eventResults2, $i, 'title'));
}
I then cycle through century and decades as previously described, and check the arrays
if ($rows > 0) //only execture if there were results from the query
{
$x = 0; //used to determine if more than one event in decade
$element = current($eventArray); //get current element in array
$prevYear = ""; //stores Event Id from previous element
//while the current element is in the current decade do the following
//also checks to make sure current element id is not equal
//to previous element id, because next function doesnt
//move if is at the end of the array
while(($element[year] <= ($cnt+9)) && ($element[year] >= $cnt) && (key($eventArray) != $prevYear))
{
//if there is more than one event in decade, add a comma
if ($x > 0) { $events .= ", "; }
//add ID and Title to events variable
$events .= key($eventArray) . $element[title];
$x++; //move counter for mult decade events
$prevYear = key($eventArray); //set var to store event id
$element = next($eventArray); //move to next element
}
}
I haven't included all the code. I left out the html that is written. But, basically, the html is output with the events.
I run the same group of code above for the second set of variables for the biblical events: $eventArray2.
Thoughts?
-Sledge