As title title.. In line 42: $data['count'] += $limit; I think it is should be count for results. $data['count'] += count($results); Sometime i just have number of records which smaller than 100 (which limited).