To return more than 25 results you need to add options.limit to your api call:
$params = array(
'version' => 3,
'sequential' => 1,
'membership_type' => 1,
'options' => array(
'limit' => 100,
),
);
$result = civicrm_api('Membership', 'get', $params);
For the second part, we want to be able to retrieve say 5,000 records. We can't really set rowCount to 5,000 because depending on the size of data, we run the risk of timing out.
The solution here is to page the results using a parameter 'options.offset':
$params = array(
'version' => 3,
'sequential' => 1,
'membership_type' => 1,
'options' => array(
'limit' => 100,
'offset' => 100 // offset value is equal to the number of results to skip
),
);
For this to work, we decide on what our ideal page size is let's say 100. We set options.limit to 100, and then we increment offset by our page size (100) on each call, until we no longer get results.
How do we know when we're done? Check the value of count in the returned result. When the returned count is less than the page size, stop.
$memberships = array();
// Initialise our pagesize and offset
$page_size = 100;
$offset = 0;
// Start out loop
do {
// Call the api
$results = civicrm_api(
'Membership',
'get',
array(
'version' => 3,
'sequential' => 1,
'membership_type' => $membership_type,
'options' => array(
'limit' => $page_size,
'offset' => $offset
)
)
);
// do something with the results if we didn't error
if ($results['is_error'] == 0) {
foreach ($results['values'] as $value) {
$memberships[] = $value;
}
}
// Increment the offset by the page size
$offset = $offset + $page_size;
} while ($results['count'] >= $page_size); // Check if we still need to fetch results