[eluser]bhenry001[/eluser]
I have noticed when working with a large amount of data from a database results, processing times slow down. I broke down the results into smaller chunks and processing time speeds up. There are more calls to MySQL, but there seems to be a speed increase. Has anyone noticed this? Or Am I just writing poor code. Below is an example of my code. Simple enough I believe.
$str='<tbody>';
$incidents=0;
$red=0;
$yellow=0;
foreach($query->result() as $row)
{
$str=$str.'<tr class='.$row->sla1.'>';
//Count the tasks
$incidents++;
switch($row->sla1) {
case 'red':
$red++;
break;
case 'yellow':
$yellow++;
break;
}
//Reformat all the date fields to display
$row->service_restored=$this->format_date($row->service_restored);
$row->create_date=$this->format_date($row->create_date);
$row->modified_date=$this->format_date($row->modified_date);
$row->progress_update=$this->format_date($row->progress_update);
$row->acknowledge_date=$this->format_date($row->acknowledge_date);
$row->datetime_service_restored=$this->format_date($row->datetime_service_restored);
//Only output the fields needed to the HTML Table
foreach($fields as $field)
{
$str=$str.'<td title="'.form_prep($row->notification_text).'" >';
if($field == 'incident_id')
{
$str=$str.anchor_popup('main/incident/'.
$row->$field,form_prep($row->$field));
}
else
{
$str=$str.form_prep($row->$field);
}
$str=$str.'</td>';
}
$str=$str.'</tr>';
} //end foreach
$query->free_result();
$str=$str.'</tbody>';
$result = array('incidents'=>$incidents,'red'=>$red,'yellow'=>$yellow,'tbody'=>$str);
return $result;