Loop through and output more than 500 results
Question
I have the following code and below I will explain what all I receive and what the output results too:
function import_employees()
{
$log = [];
$name = 'octopus_import_employees';
$settings = get_settings();
$octopus = get_octopus();
/* Create an empty array */
$ids = [];
do {
$response = $octopus->get_raw('employees', [
'id' => $ids,
'updated_at_after' => $settings['started'],
]);
$next_url = $response->paginator->next_page;
[MORE CODE]
}
} while ($next_url !== null); {
}
}
Here is the var_dump($response)
:
object(stdClass)[1318]
public 'paginator' =>
object(stdClass)[1319]
public 'total' => int 3082
public 'per_page' => int 500
public 'current_page' => int 1
public 'last_page' => int 7
public 'prev_page' => null
public 'next_page' => string 'https://oc.com/api/v1/employees/?page=2' (length=61)
public 'data' =>
array (size=500)
0 =>
object(stdClass)[1317]
public 'id' => int 6
etc..
var_dump($next_url)
returns the next_page param.
How would I be able to use the current do while call that I have and loop through all the $next_url params until it reaches null
because that’s what it always defaults too if there is nothing left.
0
loop, php
3 years
2019-10-31T11:18:10-05:00
2019-10-31T11:18:10-05:00 0 Answers
72 views
0
Leave an answer