Page 1 of 1

help with returning results from array

Posted: Mon Nov 29, 2010 4:51 pm
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?

Re: help with returning results from array

Posted: Wed Dec 01, 2010 4:33 pm
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>";

Re: help with returning results from array

Posted: Wed Dec 01, 2010 5:10 pm
by ext103
thanks i did actually find this out in the end, thanks for the reply though.