fetch(PDO::FETCH_ASSOC)) { $akzNr = $row['AkzNr']; // collect the data for one akzession $akzRows[] = $row; $firstAkzNr = $akzRows[$startIndex]['AkzNr']; // all rows where collected for the actual AkzNr if ($akzNr != $firstAkzNr) { // not need the last element here $length = count($akzRows) - $startIndex - 1; $rows = array_slice($akzRows, $startIndex, $length); $orderedResult[] = $rows; if ($rowCount >= $top) { $finished = true; break; } $startIndex = $rowCount; } $rowCount++; } // there maybe some more rows in the array $akzRows if (!$finished && ($startIndex < count($akzRows))) { $length = count($akzRows) - $startIndex; $rows = array_slice($akzRows, $startIndex, $length); $orderedResult[] = $rows; } // build the content for the response page usort($orderedResult, array($this, 'cmpTaxonData')); return $orderedResult; } /** * Compare groups of rows that share the same akzNr */ function cmpTaxonData($aRows, $bRows) { // make a difference between WissNameTax and H_WissNameTax // (all records for one akzNr should have the same WissNameTax value, // that's why we can take the first one) if ($aRows[0]['WissNameTax']) { $a = $aRows[0]['WissNameTax']; } else { $a = $aRows[0]['H_WissNameTax']; } if ($bRows[0]['WissNameTax']) { $b = $bRows[0]['WissNameTax']; } else { $b = $bRows[0]['H_WissNameTax']; } // compare the records if ($a == $b) { return 0; } return ($a < $b) ? -1 : 1; } } ?>