In other words, look at the code right after the '$next' part of the code. If you still cannot find the problem, then you need to pick one:
a) look again
b) sleep then do (a)
c) see an optician
d) give up
Your job is even easier considering the forum PHP code parser has done some of the work for you.