getConnection(); // start building the query for table BogartWebIntern $topConfigured = $database->getTop(); // we need some more to get a complete group of records to one akzNr $someMore = 20; $top = $topConfigured + $someMore; $query = "SELECT TOP $top * FROM dbo.BogartWebIntern"; // completing the query using an array with the conditions $conditions = $queryBuilder->getConditions(); $count = count($conditions); if ($count > 0) { $query .= " WHERE $conditions[0]"; } if ($count > 1) { for ($i = 1; $i < $count; $i++) { $query .= " AND $conditions[$i]"; } } // 'ORDER BY AkzNr' is required for the following code to work. // But this is only a presorting. The final sorting is optional. $query .= " ORDER BY AkzNr"; // for testing only // $htmlBuilder->addParagraph($query); // create and execute the query $stmt = $conn->query($query); $stmt->execute(); // group and sort the records $sortedResult = $arraySorter->sort($stmt, $topConfigured); // build the tables for each 'Akzession' and finally build the response page for ($akzIndex = 0; $akzIndex < count($sortedResult); $akzIndex++) { $htmlBuilder->addTablesForOneAkzession($akzIndex + 1, $sortedResult[$akzIndex]); } $htmlBuilder->printPage(); } catch (Exception $e) { die(print_r($e->getMessage())); } $stmt = null; // not calling exit() at the end of the script to avoid problems with fastcgi // exit(); ?>