Jump to content

extracting data from an API array


swingking

Recommended Posts

I have been banging my head against the wall trying to pull out data from a returned array from the Hitslink API.

here is the code that returns the data....

$params = array("account" => $username, // Create a wrapper array for SOAP params
  "password" => $password,
  "reportId" => $reportID,
  "maxRows"  => $maxRows,
  "chartHeight"  => $chartHeight,
  "chartWidth"  => $chartWidth);

// Instantiate the soapclient, pass it the WSDL location
$client = new soapclient("http://www.hitslink.com/reportWS.asmx?WSDL");


    // Call the GetData WS Function, parse and display to taste.
    $return = $client->GetData($params);
   

I added this to display the data....
while (list ($key, $val) = each ($return->GetDataResult)) {
echo "$key -> $val <br>";
}

and here is the results displayed...

Title -> Traffic History
EndDate -> 2006-11-27T14:00:00
StartDate -> 2006-11-26T15:00:00
ChartURL -> www.hitslink.com/chartfx62/temp/cft1127_03300129f56.png
ColumnDefinitions -> Object id #4
Rows -> Object id #11

What I want is the "Rows" data.

how do I extract this info into an array?

thanks!

Mark
dino432@yahoo.com
Link to comment
Share on other sites

You do it like you did the first object [b]$return->GetDataResult[/b], inside that loop you test [code]$v[/code] to see if it is another object, if it is you loop that object too!


This is just a simple example, if your object have more child obects then you will need to add some type of recursion!


[code] foreach ( $return->GetDataResult AS $pk => $pv )
{
if ( is_obj ( $pv ) )
{
echo $pk . ":<br />";

foreach ( $pv AS $ck => $cv )
{
echo "\t" . $ck . " -> " . $cv . "<br />";
}
}
else
{
echo $pk . " -> " . $pv . "<br />";
}
}[/code]


printf
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.