Hi Petrogad,

Sorry, I didn't show you the entire result, I just simplified what I got,
for phoneNumbers. Basically I do get results for title, and all other
fields, except for phoneNumbers:

I do have a responseData, results, etc.

Here is the $body print_r

Please, check it out:

http://allmybookings.com/apilocal2/google.php?q=comocomo+brussels

Here you can see, I get results, the title, even the addressLines : 0 & 1.

http://allmybookings.com/apilocal/google.php?q=comocomo+brussels

So, if the format of addressLines in the first foreach is

$search_results['results'][$i]['addressLines'] = $r->addressLines;

the phoneNumbers should be:

$search_results['results'][$i]['phoneNumbers'][] = $r->phoneNumbers;


And in the second foreach it should be:

echo $sr['addressLines'][0]."<br>";
echo $sr['addressLines'][1]."<br>";

And for the phoneNumbers:

echo $sr['phoneNumbers'][0]['number']."<br>";

Here I put the entire code in case you want to test it yourself:

You'll see what I mean

Thanks one more time,
Sebastian

<?php
require_once 'JSON.php';
if(isset($_GET['q'])) {
$start = isset($_GET['start']) ? $_GET['start'] : 0;
$url = 
'http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q='.urlencode($
_GET['q']).'&rsz=small&start='.$start;
    $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]['title'] = $r->title;
        $search_results['results'][$i]['addressLines'] = $r->addressLines;
        $search_results['results'][$i]['phoneNumbers'][] = $r->phoneNumbers;
        $search_results['results'][$i]['type'] = $r->type;
        $search_results['results'][$i]['number'] = $r->number;
        $search_results['results'][$i]['phoneNumbers'][$sr->number] =
$r->telnumber;
        $i++;
    }
     foreach($search_results['results'] as $sr) {
        echo $sr['title']."<br>";
        echo $sr['addressLines'][0]."<br>";
        echo $sr['addressLines'][1]."<br>";
        echo $sr['number'][0]."<br>";
        echo count($sr['phoneNumbers'][0])." <- 1 : gives 1 result. meaning
there is 1 phone number<br>"; // best:
        echo count($sr['phoneNumbers']['number'])." <- 2<br>"; // gives 0
results, but doesn't give an error
        echo count($sr['phoneNumbers']['number'][0])." <- 3<br>"; // gives 0
results, but doesn't give an error
        echo $sr['phoneNumbers']." <- 4<br>"; // doesn't give an error but
doesn't give a number.
        echo $sr['phoneNumbers']['number']." <- 5<br>"; // empty line
        echo $sr['phoneNumbers']['number'][0]." <- 6<br>"; // empty line
        echo $sr['phoneNumbers'][0]['number']." <- 7<br>"; // empty line
        echo $sr['phoneNumbers'][0]['number'][0]." <- 8<br>"; // empty line
        echo $sr['phoneNumbers']['number'][0]." <- 9<br>"; // empty line
        echo count($sr['phoneNumbers'][0]['number'])."<br>";
        echo $sr['telnumber'][0]." <- 10<br>"; // empty line
}
}
?>




On 05/04/09 17:57, "Petrogad" <[email protected]> wrote:

> 
> It looks like you've just copy pasted a few examples, and then re-
> pasted your initial example.
> 
> if you print_r($body) and you're resulted with:
> [phoneNumbers] => Array
>                                  (
>                                      [0] => stdClass Object
>                                          (
>                                              [type] =>
>                                              [number] => 03 232 02 10
>                                          )
>                                  )
> 
> then this line:
> foreach($body->responseData->results as $r) {
> is way off.
> 
> i see no responseData, and i see no results in that array.
> 
> i see phoneNumbers, i see type and I see number.
> 
> On Apr 5, 5:46 am, sebastian de comocomo <[email protected]>
> wrote:
>> Hi Petrogad,
>> 
>> I checked this:http://be.php.net/print_r
>> 
>> For the DOM, if I understand correctly, you are trying to tell me that the
>> info we get from Google, is a DOM, so it comes as nodes & appended Childs.
>> 
>> I just have to figure out which kind of DOM is it: map, list, element,... To
>> be able to treat the info.
>> 
>> I don't understand the difference between -> & => , are these 2 different
>> ways to assign values to a variable?
>> 
>> I understand a DOM has a name & a value, like a variable.
>> 
>> To try to understand how it works I analyze some examples:
>> 
>> In this example I understand it assigns a value to an Array called
>> $domTable, and then assigns this value to a variable called $tables, and
>> then echos the value.
>> 
>> $domTable = $dom->getElementsByTagName("table");
>> 
>> foreach ($domTable as $tables)
>> {
>>     echo DOMinnerHTML($tables);
>> 
>> }
>> 
>> Here it says something which I think it's getting
>> warmer.http://be.php.net/manual/en/class.domnodelist.php
>> You don't need to convert a DOMNodeList to an array in order iterate through
>> it using 'foreach'.  You can use foreach directly with the DOMNodeList.
>> 
>> $nodeList = $someDomDocument->getElementsbytagname('user');
>> 
>> foreach ($nodeList as $node) {
>>     echo $node->nodeValue;
>> 
>> }
>> 
>> From this example, I understand it's a Map of Nodes. But this is not
>> it.http://be.php.net/manual/en/class.domnamednodemap.php
>> You can iterate over an instance of DOMNamedNodeMap:
>> <?php
>> // suppose $node is a valid DOMElement object
>> // $node->attributes will be NULL or a valid DOMNamedNodeMap object
>> foreach ($node->attributes as $attrName => $attrNode) {}
>> 
>> http://be.php.net/manual/en/domnamednodemap.item.php
>> <?php
>> if($element->hasAttributes())
>> {
>>     $attributes = $element->attributes;
>>     if(!is_null($attributes))
>>     {
>>         foreach ($attributes as $index=>$attr)
>>         {
>>             echo $attr->name."=\"".$attr->value."\"";
>>         }
>>     }}
>> 
>> ?>
>> 
>> And here I see there is a nodeName[] within an Array, is this correct? And
>> this should be it, so the phoneNumbers are a Child within an Array.
>> 
>> http://be.php.net/dom
>> 
>> foreach($n->childNodes as $nc){
>>         if( $nc->hasChildNodes() ){
>>             if( $n->firstChild->nodeName==
>> $n->lastChild->nodeName&&$n->childNodes->length>1){
>>                 $item = $n->firstChild;
>>                 $return[$nc->nodeName][]=$this->xmlToArray($item);
>> 
>> Going back to the print_r($body):
>> [phoneNumbers] => Array
>>                                  (
>>                                      [0] => stdClass Object
>>                                          (
>>                                              [type] =>
>>                                              [number] => 03 232 02 10
>>                                          )
>>                                  )
>> 
>> CONCLUSION: it should be something like this:
>> 
>>         $search_results['results'][$i][$sr->number] = $r->telnumber;
>> 
>>         $search_results['results'][$i]['phoneNumbers'][$sr->number] =
>> $r->telnumber;
>> 
>> To get the child. I tried with quotations, and not working, neither.
>> 
>> Am I getting closer?
>> 
>> Thanks
>> Sebastian
>> 
>> On 04/04/09 17:21, "Petrogad" <[email protected]> wrote:
>> 
>> 
>> 
>>> Sebastian-
>> 
>>> Again I tell you:
>> 
>>> print_r($body);
>> 
>>> then use:
>>> http://php.net/domto understand how to use the information that is
>>> retrieved.
>> 
>>> On Apr 4, 6:43 am, sebastian de comocomo <[email protected]>
>>> wrote:
>>>> Hi Petrogad,
>> 
>>>> I do get results, I get the title, I even get the addressline which is also
>>>> an Array, but I don't manage to get the phoneNumbers.
>> 
>>>> Everything is in the same format, and I've tried all kind of combinations
>>>> in
>>>> each of the "foreach"'s.( the $r and the $sr).
>> 
>>>> I even run tests to understand how the foreach function works
>> 
>>>> http://allmybookings.com/foreach.php
>> 
>>>> For the title:
>>>> 1st. I assign $r -> title, and then for each $r->title result I print as
>>>> $sr. I don't know why this change of variable, but the title works.
>> 
>>>> I don't understand what is the relation with the PHP DOM?
>> 
>>>> What am I doing wrong?
>> 
>>>> Here is the last code with new tests:
>> 
>>>> <?php
>>>> require_once 'JSON.php';
>>>> if(isset($_GET['q'])) {
>>>> $start = isset($_GET['start']) ? $_GET['start'] : 0;
>>>> $url =
>>>> 'http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q='.urlen...
>>>> _GET['q']).'&rsz=small&start='.$start;
>>>>     $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]['title'] = $r->title;
>>>> //        $search_results['results'][$i]['phoneNumbers'] =
>>>> $r->phoneNumbers;
>>>> //        $search_results['results'][$i]['type'] = $r->type;
>>>> //        $search_results['results'][$i]['number'] = $r->number;
>> 
>>>>         $search_results['phoneNumbers'][$i]['number'] = $r->number;
>>>>         $i++;
>>>>     }
>>>>      foreach($search_results['results'] as $sr) {
>>>>         echo $sr['title']."<br>";
>>>>         echo $sr['number'][0]."<br>";
>>>>         echo count($sr['phoneNumbers'][0])." <- 1 : gives 1 result. meaning
>>>> there is 1 phone number<br>"; // best:
>>>>         echo count($sr['phoneNumbers']['number'])." <- 2<br>"; // gives 0
>>>> results, but doesn't give an error
>>>>         echo count($sr['phoneNumbers']['number'][0])." <- 3<br>"; // gives
>>>> 0
>>>> results, but doesn't give an error
>>>>         echo $sr['phoneNumbers']." <- 4<br>"; // doesn't give an error but
>>>> doesn't give a number.
>>>>         echo $sr['phoneNumbers']['number']." <- 5<br>"; // empty line
>>>>         echo $sr['phoneNumbers']['number'][0]." <- 6<br>"; // empty line
>>>>         echo $sr['phoneNumbers'][0]['number']." <- 7<br>"; // empty line
>>>>         echo $sr['phoneNumbers'][0]['number'][0]." <- 8<br>"; // empty line
>>>>         echo $sr['phoneNumbers']['number'][0]." <- 9<br>"; // empty line
>>>>         echo count($sr['phoneNumbers'][0]['number'])."<br>";
>> 
>>>> }
>>>> }
>> 
>>>> ?>
>> 
>>>> On 03/04/09 15:05, "Petrogad" <[email protected]> wrote:
>> 
>>>>> Sebastian, the answer is in front of you :)
>> 
>>>>> I'm not sure where you're getting results in:     foreach($body-
>>>>>> responseData->results as $r) {
>> 
>>>>> if the below is what you get, then re-adjust your querying.
>> 
>>>>> Also take  a look at this:
>>>>> http://php.net/dom
>> 
>>>>> Good Luck, all the answers are above.
>> 
>>>>> On Apr 3, 4:45 am, sebastian de comocomo <[email protected]>
>>>>> wrote:
>>>>>> Hi Petrogad,
>> 
>>>>>> Cool, I get this:
>> 
>>>>>> [phoneNumbers] => Array
>>>>>>                                 (
>>>>>>                                     [0] => stdClass Object
>>>>>>                                         (
>>>>>>                                             [type] =>
>>>>>>                                             [number] => 03 232 02 10
>>>>>>                                         )
>> 
>>>>>>                                 )
>> 
>>>>>> So, there is a phone number: 03 232 02 10.
>> 
>>>>>> I suppose the structure should be something like this:
>>>>>> ...
>>>>>> $search_results['results'][$i]['phoneNumbers'] = $r->phoneNumbers;
>> 
>>>>>> $search_results['results'][$i]['type'] = $r->type;
>> 
>>>>>> $search_results['results'][$i]['number'] = $r->number;
>>>>>> ...
>>>>>> echo $sr['phoneNumbers'][0]['number'];
>>>>>> ...
>>>>>> But this stops the code, in that line.
>> 
>>>>>> I also tried:
>>>>>> ...
>>>>>> $search_results['results'][$i]['phoneNumbers']['number'] = $r->newnumber;
>>>>>> ...
>>>>>> But this gives an empty record.
>> 
>>>>>> And this:
>>>>>> $search_results['results'][$i]['phoneNumbers'][$i]['number'] =
>>>>>> $r->newnumber;
>> 
>>>>>> Which gives an error -> empty page.
>> 
>>>>>> What is "stdClass Object"?
>> 
>>>>>> Thanks,
>>>>>> Sebastian
>> 
>>>>>> On 02/04/09 16:14, "Petrogad" <[email protected]> wrote:
>> 
>>>>>>> Sebastian-
>> 
>>>>>>> I would first print_r $body so you know what you're doing.  then
>>>>>>> proceed accordingly.
>> 
>>>>>>> On Apr 2, 6:40 am, Sebastian <[email protected]> wrote:
>>>>>>>> Hi,
>> 
>>>>>>>> could anyone help me out with this?
>> 
>>>>>>>> I've tried everything I can imagine.
>> 
>>>>>>>> I suppose this is correct:
>> 
>>>>>>>> echo count($sr['phoneNumbers'][0]);
>> 
>>>>>>>> To see if there are any phone numbers in the variable, isn't it?
>> 
>>>>>>>> If so, how do I get the number?
>> 
>>>>>>>> Thanks
>>>>>>>> Sebastian
>> 
>>>>>>>> On Mar 30, 2:34 pm, Sebastian <[email protected]> wrote:
>> 
>>>>>>>>> Hi,
>> 
>>>>>>>>> I've tried many different options to get thephoneNumbersfrom the
>>>>>>>>> Local Search API, but I didn't manage to do so.
>> 
>>>>>>>>> I count how many numbers are in thephoneNumbersvariable and I get 1
>>>>>>>>> or 2 depending on the record,
>> 
>>>>>>>>> count($sr['phoneNumbers'][0])
>> 
>>>>>>>>> I followed the reference guidelines, to try to do different options
>>>>>>>>> but I don't manage to do so. The guide says there are 3 variables to
>>>>>>>>> thephoneNumbers:
>> 
>>>>>>>>>                 $search_results['results'][$i]['phoneNumbers'] =
>>>>>>>>> $r->phoneNumbers;
>>>>>>>>>                 $search_results['results'][$i]['type'] = $r->type; //
>>>>>>>>> 1)
>>>>>>>>> main 2) fax
>>>>>>>>> 3) mobile
>>>>>>>>>                 $search_results['results'][$i]['number'] = $r->number;
>>>>>>>>> //
>>>>>>>>> the number
>> 
>> ...
>> 
>> read more »
> > 



--~--~---------~--~----~------------~-------~--~----~
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