Codice PHP:
$quantita = array();
for (
$b=0$b<$totdistinte$b++) {
  
$cerca mysql_query("SELECT qtacod FROM $dibart WHERE dibcod '$distinte[$b]' AND codpro = '$codici[$a]'");
  if(
mysql_num_rows($cerca) > ) {
        while(
$row2 mysql_fetch_array($cerca)) {
        
$quantita[] .= $row2['qtacod'];
       }
  }
    elseif(
mysql_num_rows($cerca) == ) {
       
$quantita[] .= '00';
   }

prova così.