Hi Jeremy

I managed to show only 1 result,

Here is the code:

<?php
require_once 'JSON.php';
if(isset($_GET['q'])) {
    $url = 
'http://ajax.googleapis.com/ajax/services/search/images?v=1.0&imgsz=medium&q
='.urlencode($_GET['q']).'&rsz=small&start=0';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $body = curl_exec($ch);
    curl_close($ch);
    $body = json_decode($body);
    $i    = 0;
    $search_results = array();
    foreach($body->responseData->results as $r) {
        $search_results['results'][$i]['unescapedUrl'] = $r->unescapedUrl;
    }
    $sr=$search_results['results'][0]; // Jeremy's suggestion to get one
result
    echo "<img src=".$sr['unescapedUrl']." width=\"100px\" height=\"100px\"
/><br />";
}
?>



On 25/03/09 17:58, "comocomo" <[email protected]> wrote:

> 
> Thanks Jeremy,
> 
> I tried:
> 
> $search_results = $body['responseData'];
> 
> And it didn't work neither
> 
> 
> 
> 
> On 25/03/09 17:35, "Jeremy Geerdes" <[email protected]> wrote:
> 
>> 
>> $search_results = $body['responseData']
>> 
>> instead of
>> 
>> $search_results = array();
>> 
>> Jeremy R. Geerdes
>> Effective website design & development
>> Des Moines, IA
>> 
>> For more information or a project quote:
>> http://jgeerdes.home.mchsi.com
>> http://jgeerdes.blogspot.com
>> http://jgeerdes.wordpress.com
>> [email protected]
>> 
>> Unless otherwise noted, any price quotes contained within this
>> communication are given in US dollars.
>> 
>> If you're in the Des Moines, IA, area, check out Debra Heights
>> Wesleyan Church!
>> 
>> And check out my blog, Adventures in Web Development, at
>> http://jgeerdes.blogspot.com
>>   !
>> 
>> 
>> On Mar 25, 2009, at 11:18 AM, sebastian de comocomo wrote:
>> 
>>> 
>>> Hi Jeremy,
>>> 
>>> I simplified it to the maximum, but still can't manage to show only 1
>>> result:
>>> 
>>> http://allmybookings.com/apiimages2/search-results.php?q=comocomo+brussels
>>> 
>>> The code:
>>> 
>>> <?php
>>> require_once 'JSON.php';
>>> 
>>> # Make sure a search-query was
>>> entered
>>> if(isset($_GET['q'])) {
>>>    # Are we on the first page?
>>>    $start =
>>> isset($_GET['start']) ? $_GET['start'] : 0;
>>> 
>>>    # The URL to the Google
>>> search API
>>> 
>>> $url =
>>> 'http://ajax.googleapis.com/ajax/services/search/images?v=1.0&imgsz=medium&q
>>> ='.urlencode($_GET['q']).'&rsz=large&start='.$start;
>>> 
>>>    # Initiate CURL
>>> 
>>> $ch = curl_init();
>>>    curl_setopt($ch, CURLOPT_URL, $url);
>>> 
>>> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
>>>    $body = curl_exec($ch);
>>> 
>>> curl_close($ch);
>>> 
>>>    # Decode the JSON returned (you need the JSON-class if
>>> json_decode is undefined)
>>>    $body = json_decode($body);
>>> 
>>>    # Build
>>> array
>>>    $search_results = array();
>>> 
>>> 
>>>    $search_results['results'][0]['unescapedUrl'] = $r->unescapedUrl;
>>> 
>>>    $sr=$search_results['results'][0]; // Jeremy's suggestion
>>> ?>
>>>    <img src="<? echo $sr['unescapedUrl']; ?>" width="100px"
>>> height="100px"
>>> /><br />
>>> <?
>>> }
>>> 
>>> 
>>> 
>>> 
>>> 
>>> On 25/03/09 16:54, "comocomo" <[email protected]> wrote:
>>> 
>>>> 
>>>> Thanks Jeremy
>>>> 
>>>> This is the url:
>>>> 
>>>> $url =
>>>> 
'http://ajax.googleapis.com/ajax/services/search/images?v=1.0&imgsz=medium&;>>>>
q
>>>> =' .urlencode($_GET['q']) .'&rsz=large&start=' .$start;
>>>> 
>>>> 
>>>> in the mean time I'll check out the other issue
>>>> 
>>>> 
>>>> On 25/03/09 15:45, "Jeremy Geerdes" <[email protected]> wrote:
>>>> 
>>>>> 
>>>>> Regarding the first issue, can you give us the url that your
>>>>> script is
>>>>> calling for the REST API so we can actually see what's returning?
>>>>> I.e., the ajax.googleapis.com/... address; NOT the allmybookings.com
>>>>> url.
>>>>> 
>>>>> Regarding the script not working, that's right.  It wouldn't work if
>>>>> you just removed the foreach.  Looking at the code you provided
>>>>> previously, you would have to call something like this:
>>>>> 
>>>>> <?php $sr=$search_results['results'][0]; ?>
>>>>> 
>>>>> Jeremy R. Geerdes
>>>>> Effective website design & development
>>>>> Des Moines, IA
>>>>> 
>>>>> For more information or a project quote:
>>>>> http://jgeerdes.home.mchsi.com
>>>>> http://jgeerdes.blogspot.com
>>>>> http://jgeerdes.wordpress.com
>>>>> [email protected]
>>>>> 
>>>>> Unless otherwise noted, any price quotes contained within this
>>>>> communication are given in US dollars.
>>>>> 
>>>>> If you're in the Des Moines, IA, area, check out Debra Heights
>>>>> Wesleyan Church!
>>>>> 
>>>>> And check out my blog, Adventures in Web Development, at
>>>>> http://jgeerdes.blogspot.com
>>>>>  !
>>>>> 
>>>>> 
>>>>> On Mar 25, 2009, at 9:25 AM, sebastian de comocomo wrote:
>>>>> 
>>>>>> 
>>>>>> Hi Jeremy
>>>>>> 
>>>>>> Regarding the 1st issue)
>>>>>> Yes, I do:
>>>>>> 
>>>>>> count($sr['phoneNumbers'][0]
>>>>>> 
>>>>>> And I get values between 1 & 2 depending on the record. So, I
>>>>>> assume
>>>>>> that
>>>>>> means there are either 1 number 'main' & a second number
>>>>>> 'fax','mobile' etc.
>>>>>> 
>>>>>> And the 2nd issue)
>>>>>> this gives 8 results
>>>>>> 
http://allmybookings.com/apiimages/search-results.php?q=comocomo%20antoin>>>>>>
e
>>>>>> %2
>>>>>> 0dansaert%2019%20brussels%201000&start=0
>>>>>> 
>>>>>> I've done tests with "foreach", "while", "for", but if I take out
>>>>>> any of the
>>>>>> foreach, such as:
>>>>>> 
>>>>>>   foreach ($body->responseData->results as $r)
>>>>>> 
>>>>>> 
> 
http://allmybookings.com/apiimages2/search-results.php?q=comocomo%20antoin>>>>>
>
> e
>>>>>> %
>>>>>> 20dansaert%2019%20brussels%201000&start=0
>>>>>> 
>>>>>> Stops working.
>>>>>> 
>>>>>> http://allmybookings.com/foreach.php
>>>>>> 
>>>>>> Any ideas?
>>>>>> 
>>>>>> Thanks,
>>>>>> 
>>>>>> Sebastian
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> On 25/03/09 12:35, "Jeremy Geerdes" <[email protected]> wrote:
>>>>>> 
>>>>>>> 
>>>>>>> First off, regarding the phone numbers issue, I wonder if you know
>>>>>>> that there are phone numbers being returned.  In other words, have
>>>>>>> you
>>>>>>> looked at the Google response and verified that they have phone
>>>>>>> number(s)?
>>>>>>> 
>>>>>>> And second, regarding limiting to only 1 result, I do not
>>>>>>> believe you
>>>>>>> can do it. The API offers two result set sizes, small and large,
>>>>>>> as
>>>>>>> of
>>>>>>> right now. Small is four results; large is eight. However, you can
>>>>>>> easily tell your script to process only one result. Just remove
>>>>>>> the
>>>>>>> foreach loop that runs through the entire results array.
>>>>>>> 
>>>>>>> Jeremy R. Geerdes
>>>>>>> Effective website design & development
>>>>>>> Des Moines, IA
>>>>>>> 
>>>>>>> For more information or a project quote:
>>>>>>> http://jgeerdes.home.mchsi.com
>>>>>>> http://jgeerdes.blogspot.com
>>>>>>> http://jgeerdes.wordpress.com
>>>>>>> [email protected]
>>>>>>> 
>>>>>>> Unless otherwise noted, any price quotes contained within this
>>>>>>> communication are given in US dollars.
>>>>>>> 
>>>>>>> If you're in the Des Moines, IA, area, check out Debra Heights
>>>>>>> Wesleyan Church!
>>>>>>> 
>>>>>>> And check out my blog, Adventures in Web Development, at
>>>>>>> http://jgeerdes.blogspot.com
>>>>>>> !
>>>>>>> 
>>>>>>> 
>>>>>>> On Mar 25, 2009, at 5:47 AM, Sebastian wrote:
>>>>>>> 
>>>>>>>> 
>>>>>>>> I also would like to limit the results to 1,
>>>>>>>> 
>>>>>>>> in PHP it would be a query like: LIMIT 1
>>>>>>>> 
>>>>>>>> but here I didn't manage to do so.
>>>>>>>> 
>>>>>>>> there is a $start, is there an $end ? i couldn't find it in the
>>>>>>>> reference section.
>>>>>>>> 
>>>>>>>> Thanks,
>>>>>>>> Sebastian
>>>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>>> 
>>>>> 
>>>>> 
>>>>>> 
>>>> 
>>>> 
>>>> 
>>>>> 
>>> 
>>> 
>>> 
>>>> 
>> 
>> 
>>> 
> 
> 
> 
> > 



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google AJAX APIs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-AJAX-Search-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to