#esta query solo entregara un valor no es necesario el while $result=mysql_query("SELECT MAX(idreg) FROM registro"); list($maximo) = mysql_fetch_row($result); echo $maximo;