I am trying to output the contents of a web service using SOAP and PHP.
This is the code I have at present:
<?php
$params = array('Criteria' => array( // create "Criteria" array
'SearchType' => 'sales',
'MinPrice'=>400000,
'MinBeds'=>2,
'MinBaths'=>1,
'ShowSold' =>true,
'sortBy'=>'bedrooms',
'SortDescending'=>true,
'Limit'=>10,
'PropertyField'=>array('ID','Image','Address1','Address2','Postcode','PriceString')
));
?>
<?php
// Call the web service function and pass the parameters setup above.
$featured_properties = $client->call('GetSalesProperties',$params, $ns);
echo '<div class="results-list">';
foreach ($featured_properties as $featured) {
echo '<article class="property">' . $featured . '</article>';
}
echo '</div>';
print_r($featured);
?>
I have added the require_once to initialise the web service and used print_r just to see what should be output. Ideally, I would like the elements in the array to be wrapped in their own tags and each record to be in a containing article.
At the moment, I'm getting Array as my echoed content.
My PHP is basic and SOAP is something new so I need help please.
you can follow this format for call to add article as root tag,
$featured_propertiest = $client->call('GetSalesProperties', array('article' => $params));
And have you declared soap client?
require_once('lib/nusoap.php');
$client = new nusoap_client('wsdl_link', true);
OK, getting somewhere and hope this clarifies for others. Firstly here's a link so you can see what I've been working towards: Sample Page
I have modified my code to this:
<?php
$params = array('Criteria' => array( // create "Criteria" array
'SearchType' => 'sales',
'MinPrice'=>400000,
'MinBeds'=>2,
'MinBaths'=>1,
'ShowSold' =>true,
'sortBy'=>'bedrooms',
'SortDescending'=>true,
'Limit'=>2,
'PropertyField'=>array('ID','Image','Address1','Address2','Postcode','PriceString')
));
?>
<?php
// Call the web service function and pass the parameters setup above.
$featured_properties = $client->call('GetSalesProperties', $params, $ns);
echo '<div class="results-list">';
foreach ($featured_properties as $featured) {
echo '<article class="property">' .
'<div class="id">' . $featured['ID'] . '</div>' .
'<span class="price">' . $featured['PriceString'] . '</span>' .
'<div class="image">' . $featured['Image'] [1] . '</div>' .
'<p class="caption">' . $featured['Image'] [1] . '</p>' .
'</article>';
}
echo '</div>';
echo '<pre>';
print_r($featured_properties);
echo '</pre>';
?>
I am now getting to my elements and wrapping them in tags for styling. Not sure how I get to the Image details though and it appears that some images have more than one to display...