I'm thinking that you could simply(?) append your query results for that field into a string, then do a little regex-ing and array manipulation:
<?php
$test = 'ABAAABBABBBBAABBAAAAAAABBABBAB';
$longestA = '';
$longestB = '';
preg_match_all('/(A+)|(B+)/', $test, $matches);
$As = array_filter($matches[1]);
if(count($As)) {
sort($As);
$longestA = array_pop($As);
}
$Bs = array_filter($matches[2]);
if(count($Bs)) {
sort($Bs);
$longestB = array_pop($Bs);
}
echo "Test data: '$test'";
echo "<br />\n";
echo "Longest streak of 'A': ".strlen($longestA)." ($longestA)";
echo "<br />\n";
echo "Longest streak of 'B': ".strlen($longestB)." ($longestB)";
(I'm sure you could clean that up a bit to reduce the code duplication, but it should give you the idea. 🙂 )