PHP - 使用多个Subreddits通过Reddit API数据进行分页

Pagination works perfectly when I request a single subreddit, like this:

$r =  'cats';
$limit = 100;
$source = "http://reddit.com/r/$r/.json?r=$r&limit=$limit&after=$after&before=$before";

When I use the API for multireddits, that's when it gives me trouble. Worse, it does it intermittently, every three pages or so.

Check it out working with one subreddit here: http://www.punk.football/mash/?r=cats

And here is the same exact file NOT working past page three with more than one subreddit: http://www.punk.football/mash/?r=cats+dogpictures

Pagination at bottom, and I've added a debug message at top of page, in the loop, and after the loop. I hope it helps.

I'm doing it like this:

$r =  'cats+dogpictures';
$limit = 100;
$source = "http://reddit.com/r/$r/.json?r=$r&limit=$limit&after=$after&before=$before";

I'm getting the after parameter as follows: $lastId = "t3_".$id; $after = $lastId;, where $id is the ID of the last item on the current page.

The first three pages work fine, then it can't get the ID once or twice, then if you keep hitting next, it will again hit three or so pages where it works, and so on.

Any help is much appreciated.