I’m using google images api to retrieve some info about images. The only problem is understanding of start param. Here is my main cycle:
// $num - necessary number of images to find
function doGoogle($query, $num)
{
// Search images until we have need number
$i = $k = $n = 0;
while(count($resultStorage) < $num)
{
$base_url = 'http://ajax.googleapis.com/ajax/services/search/images?v=1.0';
$url = $base_url;
if ($i == 0)
$url .= '&imgsz=large&q='.urlencode($query).'&start=00';
else
$url .= '&imgsz=large&q='.urlencode($query).'&start='.$k.$n;
// Request the page from google's api
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url);
$json = curl_exec($curl);
curl_close($curl);
$data = json_decode($json);
echo '<div style="clear: both"></div>Page: <b>' . $i . '</b><br />Url: <b>' . $url . '</b><br />';
// Cycle through the list of result images
foreach($data->responseData->results as $v)
{
// If we already have neccessary number of images
if (count($resultStorage) == $num) break;
// Show it up
echo "<div style='float: left'><a href='{$v->unescapedUrl}'><img src='{$v->tbUrl}' /></a></div>";
}
$i++;
$k++;
if ($k == 9) { $k = 0; $n++; }
}
};
How to manipulate with n and k? Because sometimes it returns the same pictures (cycling).
You can find my example-code at page: http://95.134.128.173/image.uploader.php (Just click Do Search).
Do you mean when you press the N or K keys it goes forward and back.
If that is the case you will need to use JavaScript, if you don’t mind them using Alt + N and Alt + K then you can use the accesskey=”n” attribute on the (already existing?) html buttons for next and previous.
If not, then I don’t get what you mean.