Alright, let me sketch what I'm trying to accomplish.
I have a form class that creates form elements based on database information. The problem is that the form takes more than 20 seconds to load on my localhost. On the web server it's even worse: the form doesn't load at all because of limited memory resources.
I was hoping you could give me some tips on optimizing my form setup. The web application I'm working on is an online park administration tool for a company that repairs playground equipment for its clients. Every few months the company needs to check the status of the playground equipment. They can do that by filling in the form that loads form fields based on a few predefined checkpoints.
Eg. "Is there still enough sand in the area around the playground device?" etc.
I have a database with a clients table, a playgrounds table, an equipment table and a checkpoints table. Every client owns a few playgrounds. Every playground consists of some devices (equipment). And every device has a few checkpoints that need to be checked. Basically the form displays input fields for every checkpoint for every device for every playground of that particular client.
Currently I query the playgrounds table to find all playgrounds the logged in client owns.
Then for every playground I display a subform.
In the subform I have another subform for every playground device.
Then I query the database to find the checkpoints for every device.
Based on those checkpoints the form displays some form fields in the devices subform.
Of course I use a lot of foreach() loops to be able to display all necessary form fields.
foreach($playgrounds as $playground) {
$devices = $playgrounds->fetchAll($playgrounds->select()->where('playground_id = ?',$playground->id);
foreach($devices as $device) {
$checkpoints = $checkpoints->fetchAll($checkpoints->select()->where('device_id = ?',$device->id);
foreach($checkpoints as $checkpoint) {
//create form fields
}
}
}
So as you can see there's LOTS of queries being performed and the more playgrounds and devices and checkpoints the more queries get performed. It just crashes the database server. I was hoping that doing just one query and then looping through the array would mean a major performance boost.