I ran tests with the example and it is running as you explained.
I tried to comment the code as much as possible in a simple way.
$limit = 10;
$counter = 1;
$categoria = null;
while( ... )
{
// verifica se mudou a categoria, e inicia o contador se for maior que 1
if( $categoria !== $row['categoria'] and $counter > 1 )
$counter = 1;
if( $counter === 1 )
{
echo $e['categoria'];
}
else
{
echo '<div style="display:none;">' . $e['categoria'] . '</div>';
// reinicia o contador se for maior que o decimo item
if( $counter === $limit ) $counter = 0;
}
// incrementa o contador e grava a categoria atual
$counter++;
$categoria = $e['categoria'];
}
Some situations to illustrate grouping
• Category ['A'] 10 records
»1st visible and 9 hidden
• Category ['A'] 15 records
»1st visible and 9 hidden + 1 visible and 4 hidden
• category ['A'] 10 records | category ['B'] 5 records
»1 visible and 9 hidden (CAT-A) + 1 visible and 4 hidden (CAT-B)
• category ['A'] 5 records | category ['B'] 10 records
»1st visible and 4 hidden (CAT-A) + 1 visible and 10 hidden (CAT-B)