Formula 1 is the contribution to the magnetic field from the small segment of the coil of length $dl$ shown in the lower portion of Figure 1. That piece of coil has current $dI = N I\, dl/l$ flowing through it where $N$ is the number of turns in the coil, $I$ is the current per turn, and $l$ is the length of the coil. From the hyperphysics site (or by integrating the Biot-Savart law), the axial field from this loop is:
$$B_z = \frac{\mu_0}{4\pi}(2\pi r) dI\frac{ r}{(r^2+z^2)^{3/2}} = \frac{\mu_0 r^2 dI}{2 y^3}$$
where $y=(r^2+z^2)^{1/2}$ is the distance from the measurement point to the rim of the loop and $r$ is the coil radius. Substituting the formula for $dI$ gives you the first equation.
The second equation is the integral of the above over the length $l$. The integral is first converted to an integral over angle $\theta$ via $\sin \theta = r/y$ and $\sin\theta\,dl = y\,d\theta$:
$$B = \int\frac{\mu_0 r^2 dI}{2 l y^3} = \frac{\mu_0 N I}{2 l} \int \frac{r^2 dl}{y^3} = \frac{\mu_0 N I}{2 l} \int_{\theta_1}^{\theta_2} \sin \theta \, d\theta$$
The Amperian Loop centered at the axis of the solenoid encloses no current. This is true.
You note two rules.
- By Ampere's Law, there is no magnetic field.
- The solenoid has a magnetic field.
You think 1. and 2. contradict. However, realize that Ampere's Law only describes the net magnetic field along the Amperian Loop. It does not say anything about other magnetic fields. So let's modify the rules.
- By Ampere's Law, there is no net magnetic field along the Amperian Loop.
- The solenoid has a magnetic field.
To see why 1. and 2. are true and don't contradict, let's consider an ideal example, then generalize.
Ideal Example
The magnetic field lines within an infinitely long solenoid are perfectly parallel with the central axis of the solenoid. This is consistent with 2.
If you consider a circle centered at the solenoid's central axis, realize that all magnetic field lines are perpendicular to the circle.
So, there are no magnetic field lines that go along the Amperian Loop. This is consistent with 1.
General Example
In the real world, we can't have infinitely long solenoids. Real world solenoids deviate from the ideal solenoid.
A single wire loop has a circularly symmetric magnetic field. Similarly, a stack of single wire loops have a circularly symmetric magnetic field. This is consistent with rule 2.
Since the solenoid is made up of circles, note that any deviation from the ideal must be circularly symmetric.
By circular symmetry, there is no net magnetic field along the circular Amperian Loop. This is consistent with rule 1.
Conclusion
Rules 1 and 2 hold for all solenoids, and don't contradict each other.
(P.S. I'm pretty sure, but cannot prove, that real-world solenoids have magnetic field lines that deviate radially outwards from the central axis, radially perpendicular to the Amperian Loop. So, there is no single magnetic field line that contributes to the Amperian Loop, and we don't even need to consider circular symmetry.)
Best Answer
You made a mistake - the number of turns per unit length in a torus depends on where you are measuring. On the inner surface they are a little closer than on the other surface.
Because of this, the expression for the toroidal coil should be
$$B = \frac{\mu N I}{2\pi r}$$
This means that the field is a little stronger towards the inner radius of the toroid than towards the outer radius. For the derivation, see http://hyperphysics.phy-astr.gsu.edu/hbase/magnetic/toroid.html