views:

56

answers:

1

hi sir..i read your post on

http://stackoverflow.com/questions/1784114/simple-php-script-to-retrieve-google-keyword-search-completion

and i was wondering how would you go 'echo' the next page? here's my script..

$search = 'query';

$x = json_decode( file_get_contents( 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=' . urlencode( $search ) ) );

echo $x->responseData->results[0]->url;

i was able to 'echo' out the url, i am stucked in going to the next page and 'echo' out the next url's

thanks sir

A: 

You change the index:

echo $x->responseData->results[1]->url;

To loop through all:

foreach ($x->responseData->results as $r) {
    echo $r->url, "\n";
}

You can inspect the complete result with var_dump($x);.

To retrieve another page of results, you can use the start parameter, e.g.:

$x = json_decode(
    file_get_contents(
    'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&start=4&q='
    . urlencode( $search )));

You can request 8 results instead of 4 with rsz=large.

Artefacto
it is displaying the results..in the script. it will only display about 4 results..what i wanted to know is how to display the results on the next page
kapitanluffy
ohai thanks :)i actually did that already. i was enlightened after reading 'start=4'what i did is 'start=1' where currentpageindex is still 0 haha xD
kapitanluffy
Here is the documentation http://code.google.com/apis/ajaxsearch/documentation/#fonje
Mike B
may i ask another question? is there a way to know the maximum pages? i tried to count($x->pages) and it only returns 8
kapitanluffy
@kapi There's `$x->responseData->cursor->estimatedResultCount`. But it's estimated. If you wanted to retrieve all results, you'd have to advance `start` until you received nothing back.
Artefacto
thanks very much @arte..thats what im actually doing right now :)
kapitanluffy
it seems like it returns only limited results. like when i search for the word 'kapitanluffy' the search ends in 'start=56'wherein google it exceeds up to start=200+
kapitanluffy
are there any other way to get more results??
kapitanluffy