$con="SELECT ins_inspec, count(ins_inspec) FROM am_inspeccion GROUP BY ins_inspec"; $exe_sql=mysql_query($con); while ($row = mysql_fetch_row($exe_sql)) { echo "$row[0]"; $con="SELECT count(ins_estado) FROM am_inspeccion where ins_inspec = '$row[0]' GROUP BY ins_estado"; $con_sql=mysql_query($con); while ($q=mysql_fetch_array($con_sql)) { foreach($q as $indice=>$valor) { if (is_int($indice)) { echo "".$valor.""; } } } echo""; }