I am creating a PHP class that uses a third-party API. The API has a method with this request URL structure:
https:
Where "x" is the page number.
Each page returns 50 sales, and I need to return an undefined number of pages for each user (depending on the user's sales) and save some data from each sale.
I have already created some methods that receive data from a URL, decode and create a new array with the necessary data, but only with the request of the first page.
Now I want to create a method that checks if there is another page, and if so, get it and do the check again
How to check if there is another page? And how to create a loop that gets another page, if any?
I already have this code, but it creates an infinite loop.
require('classes/class.example_api.php'); $my_class = new Example_API; $page = 1; $sales_url = $my_class->sales_url( $page ); $url = $my_class->get_data($sales_url); while ( !empty($url) ) { $page++; $sales_url = $my_class->sales_url( $page ); $url = $my_class->get_data($sales_url); }
I do not use CURL, I use file_get_content . When I request a page out of range, I get this result:
string(2) "[]"
And this is different after json_decode :
array(0) { }
api php pagination
Themes creator
source share