There is an API that I'm integrating with and one of the weaknesses of it is that you can't get a results count from a single query -- it only returns 1000 results at a time, so you have to keep running the query, returning the next set of results until you get a set that is less than 1000 (so you know you've reached the limit).
I need a php script that can help determine how many results there are in the least amount of queries.
So for example, say there are 585,783 records (but I don't know that to start with)
I will give the script a starting number like 500.
I will run my query to see how many results there are for page 500. If there are 1000 result (the max), then I know that it's on a higher page, so the script should double that to 1000. I check page 1000 and see there are no results, so I know that is too high. So the script now needs to return the midpoint between 500 and 1000 ... so I check to see if there are results for page 750. No result? Then I need the midpoint between 500 and 750 ... and so on until I find a midpoint number the returns results greater than 0 but less than 1000.
This way rather than having to run the API script 585 times, I run it through only 8 times (in this example)
try 500 = greater
try 1000 (500 * 2) = less
try 750 (midpoint btwn 500 and 1000) = less
try 625 (midpoint btwn 500 and 750) = less
try 563 (midpoint, rounded, btwn 500 and 625) = more
try 594 (midpoint, rounded, btwn 563 and 625) = less
try 579 (you get the point) = more
try 585 (BINGO ... results for this page are 783 ... greater than zero, less than 1000)
So I'll provide the starting number and the number of results from that query, then this script needs to provide me with a new number to try. I would like to be able to use this within a 'while' statment so my query repeats until it finds the result.