SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SOAP / Object id #2 - help

    I'm very new to the SOAP stuff and still getting into php, but I've gotten to a point where I need a little guidance.

    I found on Zend's website some simple SOAP stuff and thought I'd toss myself into it.

    I'm using this to connect to the wsdl link and display the results, but i'm stuck, it keep returning "Object id #2". Where have I gone wrong?

    PHP Code:
    <?php
      $s1 
    "Portland";
      
    $s2 "UT";


      
    $client = new SoapClient("http://www.atomic-x.com/xmlservices/latlon.asmx?wsdl");
      try {
        
        
    $result1 $client->SearchByState($s2);
        
    //$result2 = $client->SearchByCity($s1);
        
    echo "<pre>\n";
        echo 
    $result1 "<br />";
        echo 
    "\n</pre>\n";
      } catch (
    SoapFault $exception) {
        echo 
    $exception;      
      }
    ?>
    i want to be a nerd....

  2. #2
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $result1 is an object. If you want to use a member of the object, you can see what is being returned with:
    PHP Code:
     echo'<pre>';
     
    print_r($result1);
     echo
    '</pre>'
    Then just call the members similar to how you'd call a member of an array:
    PHP Code:
     echo $result1->var_name1
     
    echo $result1->var_description 
    etc.
    Aaron Brazell
    Technosailor



  3. #3
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and if it returns something like this:
    PHP Code:
    stdClass Object 
    (     [SearchByStateResult] => stdClass Object         
    (             
    [
    schema] => 
                 [
    any] => 
             ) 

    there's something wrong right? either i'm sending the wrong information or it's returning nothing?
    i want to be a nerd....

  4. #4
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If it shows up like that, you'd access it as you would a multidimensional array:
    PHP Code:
    echo $result1[SearchByStateResult]->schema[any
    or alternatively (esp if there might be more results than this, feed it through a foreach loop:
    PHP Code:
    foreach($result1 as $result)
    {
      echo 
    $result->schema[any]

    I think.
    Aaron Brazell
    Technosailor



  5. #5
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    using the first suggestion tells me that it can't be used that way:
    Fatal error: Cannot use object of type stdClass as arraythe second nets me a < and that's it.

    if i do it by state, according to the website, it should return all lat/lon for the entire state, but i'm not sure how to get it to return that.

    i found that it requires the 2 digit state and made that change, but it still doesn't yeild any response.

    if you need to look at anything on it, it's here: click analyze wsdl
    Last edited by vr6stress; May 26, 2006 at 10:11. Reason: change message
    i want to be a nerd....

  6. #6
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So what are you trying to get? Lat/Long of Portland, UT?

    Edit: I see what you're trying to do. One sec.
    Aaron Brazell
    Technosailor



  7. #7
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems there's key information missing from the documentation. I can't get anything more than an object with more than schema and any as elements.
    Aaron Brazell
    Technosailor



  8. #8
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    opshang on - that one i couldn't get ot work (no it was EITHER state or city)

    but i found one that returns results, it's a soccer one, but i still run into the problem of saying that it can't use the stdClass as an array...

    this is the return i get:
    HTML Code:
     stdClass Object
      (
          [TeamsResult] => stdClass Object
              (
                  [tTeamInfo] => Array
                      (
                          [0] => stdClass Object
                              (
                                  [sName] => Angola
                                  [sCountryFlag] => http://www.dataaccess.nl/wk2006/flags/ANGOLA__.jpg
                              )
      
                          [1] => stdClass Object
                              (
                                  [sName] => Argentinia
                                  [sCountryFlag] => http://www.dataaccess.nl/wk2006/flags/ARGENTIN.jpg
                              )
      
                          [2] => stdClass Object
                              (
                                  [sName] => Australia
                                  [sCountryFlag] => http://www.dataaccess.nl/wk2006/flags/AUSTRALI.jpg
                              )
      
                          [3] => stdClass Object
                              (
                                  [sName] => Brazil
                                  [sCountryFlag] => http://www.dataaccess.nl/wk2006/flags/BRAZIL__.jpg
                              )
      
                          [4] => stdClass Object
                              (
                                  [sName] => Costa Rica
                                  [sCountryFlag] => http://www.dataaccess.nl/wk2006/flags/COSTA___.jpg
     )
    but i'm still not clear on how to loop over that when it keeps telling me the object can't be used as an array
    Last edited by vr6stress; May 26, 2006 at 11:11. Reason: o
    i want to be a nerd....

  9. #9
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Give me the code you used to generate that real quick.
    Aaron Brazell
    Technosailor



  10. #10
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php

    $client 
    = new SoapClient("http://www.dataaccess.nl/wk2006/footballpoolwebservice.wso?WSDL");
      try {
        
        
    $result = ($client->Teams());
        
        echo 
    "<pre>";
           
    print_r($result);
        echo 
    "</pre>";
        
        } catch (
    SoapFault $exception) {
        echo 
    $exception;      
      }
    ?>
    i want to be a nerd....

  11. #11
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it. Not prettiest code I've ever written, but it works:

    PHP Code:
    <?php
    $client 
    = new SoapClient("http://www.dataaccess.nl/wk2006/footballpoolwebservice.wso?WSDL");
        try 
        {
        
    $result = ($client->Teams());
        foreach(
    $result->TeamsResult as $teamstuff)
             {
              foreach(
    $teamstuff as $indiv)
                  {
                   echo 
    '<img src="'.$indiv->sCountryFlag.'"> '.$indiv->sName.'<br />';        
                  }
               }
           } 
        catch (
    SoapFault $exception
        {
            echo 
    $exception;      
        }
    ?>
    Example: http://thenotsofreestate.com/latlong.php
    Aaron Brazell
    Technosailor



  12. #12
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    THANKS!

    would mind stepping me through the logic of this (use small words) so I can try to get it through my thick skull how this works, and why it works the way it does?
    i want to be a nerd....

  13. #13
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    //Initialize SOAP object
    $client = new SoapClient("http://www.dataaccess.nl/wk2006/footballpoolwebservice.wso?WSDL");
        try 
        {
        
    // Get Raw XML results
        
    $result = ($client->Teams());
        
    /* 
            Loop through the first object. Returns data such as:
            Array
                (
                    [0] => stdClass Object
                        (
                        [sName] => Angola
                        [sCountryFlag] => [url]http://www.dataaccess.nl/wk2006/flags/ANGOLA__.jpg[/url]
                        )

                    [1] => stdClass Object
                        (
                        [sName] => Argentinia
                        [sCountryFlag] => [url]http://www.dataaccess.nl/wk2006/flags/ARGENTIN.jpg[/url]
                        )

                    [2] => stdClass Object
                        (
                        [sName] => Australia
                        [sCountryFlag] => [url]http://www.dataaccess.nl/wk2006/flags/AUSTRALI.jpg[/url]
                        )
        */
        
    foreach($result->TeamsResult as $teamstuff)
             {
             
    /* 
                 Loop through second object. Returns data such as:
                 stdClass Object
                    (
                    [sName] => Angola
                    [sCountryFlag] => [url]http://www.dataaccess.nl/wk2006/flags/ANGOLA__.jpg[/url]
                    )
                    
                stdClass Object
                    (
                    [sName] => Argentinia
                    [sCountryFlag] => [url]http://www.dataaccess.nl/wk2006/flags/ARGENTIN.jpg[/url]
                    )
             */
              
    foreach($teamstuff as $indiv)
                  {
                  
                   echo 
    '<img src="'.$indiv->sCountryFlag.'"> '.$indiv->sName.'<br />';        
                  }
               }
           } 
        catch (
    SoapFault $exception
        {
            echo 
    $exception;      
        }
    ?>
    Aaron Brazell
    Technosailor




Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •