Last active
August 29, 2015 14:11
-
-
Save mkhairul/6a8a0def23ef3ecd0ec1 to your computer and use it in GitHub Desktop.
Retrieve all records from Parse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Based on http://stackoverflow.com/questions/17246991/parse-retrieve-more-then-1000-rows/17288679#17288679 | |
function getAllRecords($className, $loopCount=0, $result=array()) | |
{ | |
$limit = 100; | |
$query = new ParseQuery($className); | |
$query->limit($limit); | |
$query->skip($limit * $loopCount); | |
try{ | |
$query_result = $query->find(); | |
if(count($query_result) > 0) | |
{ | |
for($i = 0; $i < count($query_result); $i++) | |
{ | |
$object = $query_result[$i]; | |
$result[] = $object; | |
} | |
$loopCount++; | |
$result = getAllRecords($className, $loopCount, $result); | |
} | |
else | |
{ | |
return $result; | |
} | |
} catch (ParseException $ex) { | |
echo "error!" . print_r($ex); | |
} | |
return $result; | |
} | |
$tmp = getAllRecords('sets'); | |
echo 'total records fetched: ' . count($tmp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment