help with returning results from array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ext103
Forum Newbie
Posts: 3
Joined: Wed Nov 24, 2010 6:16 am

help with returning results from array

Post by ext103 »

hello all,

im adding the seostats project that is hosted on google to one of my plugins for wordpres to allow analasis of site in the backend.

so far i have go absolutly everything working, except for the one i really want.

the function i am having trouble with is getting the array items to list yahoo backlinks.

its all wrapped up in a class with ublic and private functions, but the public one just redirects to the private one for this. here it is:

Code: Select all

    // -------------------------------------------------------------------
    // Private Function to return detailed backlink data from yahoo
    // -------------------------------------------------------------------
    private function yahooLl(){
      // -------------------------------------------------------------------
      // Save yahoo result page to string using curl
      // -------------------------------------------------------------------
      $str = $this->cURL('http://search.yahooapis.com/SiteExplorerService/V1/inlinkData?appid=oVFwwjnV34GEEZTLB3K_WW1YC9_VysYbCYQ4szoXTAHZscrDvMazUpFR7TR0wchmlA--&results=100&output=json&query=http://'.urlencode($this->domain));
      // -------------------------------------------------------------------
      // Decode JSON response
      // -------------------------------------------------------------------
      $data = json_decode($str);
      // -------------------------------------------------------------------
      // Write results array
      // -------------------------------------------------------------------
      $result = array();
      for ($i=0;$i<sizeof($data->ResultSet->Result);$i++){
        $result []= array(
                    'URL' => $data->ResultSet->Result[$i]->Url,
                    'Anchortext' => $data->ResultSet->Result[$i]->Title
        );
      }
      // -------------------------------------------------------------------
      // Return array
      // -------------------------------------------------------------------
      return $result;   
    } // End of private function yahooLl


okay, now in my template file i have this

Code: Select all

print_r ($obj->YahooLinkDetails());
which dumps all of it. (note i am calling the public function, i can assure this only returns the private function so only need to post private one so no issues there.)


ot prints it like this:

Code: Select all

	Array ( [0] => Array ( [URL] => http://www.motionworks.com.au/ [Anchortext] => After Effects and Cinema 4D Training ) [1] => Array ( [URL] => http://www.spizak.com/ [Anchortext] => Adam Spizak - Illustrator and Designer. Version 4. ) [2] => Array ( [URL] => http://www.longliveanalog.com/ [Anchortext] => Long Live Analog ) [3] => Array ( [URL] => http://2007.photobloggies.org/ [Anchortext] => The 2007 Photobloggies ) 
which at least i now its working right.

what i want ot do is call the [URL] and the [Anchortext] seperatley so i can add them to a table in seperate cells.

ive tried all sorts of things but just cannot get my head around the multidimensions array.

please can someone help me out?
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: help with returning results from array

Post by Weiry »

To print out to separate cells, try using a foreach on the entire array:

Code: Select all

print "<table>";
foreach($obj->YahooLinkDetails() as $link){
    print "<tr><td>".$link['URL']."</td><td>".$link['Anchortext']."</td></tr>";
}
print "</table>";
ext103
Forum Newbie
Posts: 3
Joined: Wed Nov 24, 2010 6:16 am

Re: help with returning results from array

Post by ext103 »

thanks i did actually find this out in the end, thanks for the reply though.
Post Reply