I've had that happen to me before too. It makes you crazy until you see it.
What happened was you cut too much off the top of the data in the first line: x=h(x,d,<a class="downgif")
There is an additional <td>(torrent date)</td> just before that.
As a result, the first hit's Q array has 4 lines, but all results that follow have 5.
So when consecutive hits were run through the script no data was found where it was looking because every t=array(q,N) is off by one.
I also made a few other minor changes.
I added 'vacuum' which just makes it easier to debug.
I also changed what you were using as a pointer. Z is better because it gets reset to 0 automatically when you change the t=array().
Did any of that make sense? Working script is attached.