The first part of the query is fine up and and including the LIMIT clause. If a figure or range is left off from LIMIT the server automagically appends 0, 30 as a range.
After the limit query are a bunch of what appear to be UDF's or custom functions called from PHP script.
A google search for "LIMIT made by require, require_once," will show numerous instances of this snippet of code.. I'm just not sure why it's borking for me.