Codice PHP:
$i=0;
while(...){
$i++;
if(
$i==1){
echo 
'<tr>';
}
//tutto il resto
if($i==3){
$i=0;
echo 
'</tr>';
}