Pirate
25-10-2005, 12:41 PM
I'm stuck on a bit of php coding.
Heres the run down.
The script is a search script, it uses a webservice and thanks to Dwarfthrowers help that side all works perfectly. But my problem comes from the returned arrays.
If the search finds multiple people, it returns this array.
Array
(
[PhoneSearchResult] => Array
(
[Phone] => Array
(
[PhoneItem] => Array
(
[0] => Array
(
[PIN] => 0
[HIN] => 0
[GIVEN_NAME_1] => George
[GIVEN_NAME_2] => J
[GIVEN_NAME_3] =>
[SURNAME] => Bums
[AD1] => 666 MOUNTAIN RD
[FUN] =>
[TN1] => 666
[THN] => MOUNTAIN
[THT] => RD
[LOC] => MOUNTAINDALE
[STT] => NSW
[PCD] => 2347
[BG1] =>
[PDN] =>
[ALN] =>
[SOURCE] => Phone
[SOURCEDATE] => 25/08/2005 12:00:00 AM
[PUBLIC_NUMBER] => 0123456789
[FCS_USAGE_CODE] => R
[FCS_TYPE_OF_SERVICE] =>
[COMPANY_NAME] =>
)
[1] => Array
(
[PIN] => 0
[HIN] => 0
[GIVEN_NAME_1] => Garry
[GIVEN_NAME_2] =>
[GIVEN_NAME_3] =>
[SURNAME] => Fubble
[AD1] => 12 BORTHCOTT RD
[FUN] =>
[TN1] => 12
[THN] => BORTHCOTT
[THT] => RD
[LOC] => WALOR PARK
[STT] => NSW
[PCD] => 3256
[BG1] =>
[PDN] =>
[ALN] =>
[SOURCE] => PHONE
[SOURCEDATE] => 8/10/2004 12:00:00 AM
[PUBLIC_NUMBER] => 01233456867
[FCS_USAGE_CODE] => R
[FCS_TYPE_OF_SERVICE] => GSM
[COMPANY_NAME] =>
)
[2] => Array
(
[PIN] => 0
[HIN] => 0
[GIVEN_NAME_1] => Tom
[GIVEN_NAME_2] =>
[GIVEN_NAME_3] =>
[SURNAME] => Farts
[AD1] => 54 WEATBOM ST
[FUN] =>
[TN1] => 54
[THN] => WEATBOM
[THT] => ST
[LOC] => RANMORE
[STT] => NSW
[PCD] => 2458
[BG1] =>
[PDN] =>
[ALN] =>
[SOURCE] => Phone
[SOURCEDATE] => 13/09/2005 12:00:00 AM
[PUBLIC_NUMBER] => 021354987
[FCS_USAGE_CODE] => R
[FCS_TYPE_OF_SERVICE] =>
[COMPANY_NAME] =>
)
)
)
[Credit] => Array
(
[Total] => 88256
)
)
)
But if it only finds one person it returns this array
Array
(
[PhoneSearchResult] => Array
(
[Phone] => Array
(
[PhoneItem] => Array
(
[PIN] => 0
[HIN] => 0
[GIVEN_NAME_1] => Tom
[GIVEN_NAME_2] =>
[GIVEN_NAME_3] =>
[SURNAME] => Farts
[AD1] => 54 WEATBOM ST
[FUN] =>
[TN1] => 54
[THN] => WEATBOM
[THT] => ST
[LOC] => RANMORE
[STT] => NSW
[PCD] => 2458
[BG1] =>
[PDN] =>
[ALN] =>
[SOURCE] => Phone
[SOURCEDATE] => 13/09/2005 12:00:00 AM
[PUBLIC_NUMBER] => 021354987
[FCS_USAGE_CODE] => R
[FCS_TYPE_OF_SERVICE] =>
[COMPANY_NAME] =>
)
)
[Credit] => Array
(
[Total] => 88266
)
)
)Notice it drops the numbering on the array. This is my problem, without this number it goes screwy and the results are all garbled.
What I am trying to do is create a bit of code that loads a different table content if the array isn't numbered. And this is where I am very stuck as I can't find anything to tell the script that "if this value is nothing, then load this code"... sorry if this is confusing, Im not too good with terminology. Below is the script I'm using. <?php
/*
* $Id: wsdlclient1.php,v 1.2 2004/03/15 23:06:17 snichol Exp $
*
* WSDL client sample.
*
* Service: WSDL
* Payload: document/literal
* Transport: http
* Authentication: none
*/
require_once('../nusoap-0.7.2/lib/nusoap.php'); // Tony's path
//require_once('../lib/nusoap.php'); // Gabe's path
$proxyhost = isset($_POST['proxyhost']) ? $_POST['proxyhost'] : '';
$proxyport = isset($_POST['proxyport']) ? $_POST['proxyport'] : '';
$proxyusername = isset($_POST['proxyusername']) ? $_POST['proxyusername'] : '';
$proxypassword = isset($_POST['proxypassword']) ? $_POST['proxypassword'] : '';
$client = new soapclient('http://search.fcsonline.com.au/FCSSearchWS/FCSSearch.asmx?WSDL', true,
$proxyhost, $proxyport, $proxyusername, $proxypassword);
$fcsuser = '';
$fcspass = '';
//$fcsuser = $_GET['user'];
//$fcspass = $_GET['pass'];
$auth="<AuthHeader xmlns=\"http://202.125.163.83/FCSSearchWS/FCSSearch.asmx\"><UserName>$fcsuser</UserName><Password>$fcspass</Password></AuthHeader>";
$client->setHeaders($auth);
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
// Doc/lit parameters get wrapped
$strPin = $_GET['pin'];
$strName1 = '';
$strName2 = $_GET['name2'];
$strName3 = $_GET['name3'];
$strSurname = 'Brisciani';
$strUnit = $_GET['unit'];
$strNumLow = $_GET['numlow'];
$strNumHigh = $_GET['numhigh'];
$strStreet = $_GET['street'];
$strSuburb = $_GET['suburb'];
$strState = $_GET['state'];
$strPostcode = $_GET['postcode'];
$strBuildname = $_GET['buildname'];
$strPObox = $_GET['pobox'];
$strReference = $_GET['ref'];
$param = array( 'PIN' => $strPin,
'GivenName1' => $strName1,
'GivenName2' => $strName2,
'GivenName3' => $strName3,
'Surname' => $strSurname,
'UnitNumber' => $strUnit,
'StreetNumberLow' => $strNumLow,
'StreetNumberHigh' => $strNumHigh,
'StreetName' => $strStreet,
'Suburb' => $strSuburb,
'State' => $strState,
'Postcode' => $strPostcode,
'BuildingName' => $strBuildname,
'POBox' => $strPObox,
'ClientRef' => $strReference
);
$result = $client->call('PhoneSearch', array('parameters' => $param), '', '', false, true);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
/***
echo "<pre>"; //You can uncomment this stuff to get a look at the returned array
print_r($result);
echo "</pre>";
***/
//We can work our way down through the $result to get what we need:
$PhoneSearchResult = $result['PhoneSearchResult'];
$Phone = $PhoneSearchResult['Phone'];
$PhoneItem = $Phone['PhoneItem']; // <-- That's the one we want to loop through
//Set up our array to hold the post codes
$pCodes = array();
// $pCodeCount = 0;
echo "<table border=\"1\">";
echo "<tr><th>Surname</th><th>Given Name</th><th>Address</th><th>Suburb</th><th>State</th><th>Post Code</th><th>Phone</th></tr>";
foreach($Phone as &$item){
echo "<tr>";
echo "<td>single";
echo $item['SURNAME'];
echo "</td>";
echo "<td>";
echo $item['GIVEN_NAME_1'];
echo "</td>";
echo "<td>";
echo $item['AD1'];
echo "</td>";
echo "<td>";
echo $item['LOC'];
echo "</td>";
echo "<td>";
echo $item['STT'];
echo "</td>";
echo "<td>";
echo $item['PCD'];
echo "</td>";
echo "<td>";
echo $item['PUBLIC_NUMBER'];
echo "</td>";
echo "</tr>";
}
if ($somthing='0') { //THIS IS WHERE I'M STUCK
foreach($PhoneItem as &$item){
echo "<tr>";
echo "<td>1";
echo $item['SURNAME'];
echo "</td>";
echo "<td>";
echo $item['GIVEN_NAME_1'];
echo "</td>";
echo "<td>";
echo $item['AD1'];
echo "</td>";
echo "<td>";
echo $item['LOC'];
echo "</td>";
echo "<td>";
echo $item['STT'];
echo "</td>";
echo "<td>";
echo $item['PCD'];
echo "</td>";
echo "<td>";
echo $item['PUBLIC_NUMBER'];
echo "</td>";
echo "</tr>";
}
}
echo "</table>";
}
}
//echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
//echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
//echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
Heres the run down.
The script is a search script, it uses a webservice and thanks to Dwarfthrowers help that side all works perfectly. But my problem comes from the returned arrays.
If the search finds multiple people, it returns this array.
Array
(
[PhoneSearchResult] => Array
(
[Phone] => Array
(
[PhoneItem] => Array
(
[0] => Array
(
[PIN] => 0
[HIN] => 0
[GIVEN_NAME_1] => George
[GIVEN_NAME_2] => J
[GIVEN_NAME_3] =>
[SURNAME] => Bums
[AD1] => 666 MOUNTAIN RD
[FUN] =>
[TN1] => 666
[THN] => MOUNTAIN
[THT] => RD
[LOC] => MOUNTAINDALE
[STT] => NSW
[PCD] => 2347
[BG1] =>
[PDN] =>
[ALN] =>
[SOURCE] => Phone
[SOURCEDATE] => 25/08/2005 12:00:00 AM
[PUBLIC_NUMBER] => 0123456789
[FCS_USAGE_CODE] => R
[FCS_TYPE_OF_SERVICE] =>
[COMPANY_NAME] =>
)
[1] => Array
(
[PIN] => 0
[HIN] => 0
[GIVEN_NAME_1] => Garry
[GIVEN_NAME_2] =>
[GIVEN_NAME_3] =>
[SURNAME] => Fubble
[AD1] => 12 BORTHCOTT RD
[FUN] =>
[TN1] => 12
[THN] => BORTHCOTT
[THT] => RD
[LOC] => WALOR PARK
[STT] => NSW
[PCD] => 3256
[BG1] =>
[PDN] =>
[ALN] =>
[SOURCE] => PHONE
[SOURCEDATE] => 8/10/2004 12:00:00 AM
[PUBLIC_NUMBER] => 01233456867
[FCS_USAGE_CODE] => R
[FCS_TYPE_OF_SERVICE] => GSM
[COMPANY_NAME] =>
)
[2] => Array
(
[PIN] => 0
[HIN] => 0
[GIVEN_NAME_1] => Tom
[GIVEN_NAME_2] =>
[GIVEN_NAME_3] =>
[SURNAME] => Farts
[AD1] => 54 WEATBOM ST
[FUN] =>
[TN1] => 54
[THN] => WEATBOM
[THT] => ST
[LOC] => RANMORE
[STT] => NSW
[PCD] => 2458
[BG1] =>
[PDN] =>
[ALN] =>
[SOURCE] => Phone
[SOURCEDATE] => 13/09/2005 12:00:00 AM
[PUBLIC_NUMBER] => 021354987
[FCS_USAGE_CODE] => R
[FCS_TYPE_OF_SERVICE] =>
[COMPANY_NAME] =>
)
)
)
[Credit] => Array
(
[Total] => 88256
)
)
)
But if it only finds one person it returns this array
Array
(
[PhoneSearchResult] => Array
(
[Phone] => Array
(
[PhoneItem] => Array
(
[PIN] => 0
[HIN] => 0
[GIVEN_NAME_1] => Tom
[GIVEN_NAME_2] =>
[GIVEN_NAME_3] =>
[SURNAME] => Farts
[AD1] => 54 WEATBOM ST
[FUN] =>
[TN1] => 54
[THN] => WEATBOM
[THT] => ST
[LOC] => RANMORE
[STT] => NSW
[PCD] => 2458
[BG1] =>
[PDN] =>
[ALN] =>
[SOURCE] => Phone
[SOURCEDATE] => 13/09/2005 12:00:00 AM
[PUBLIC_NUMBER] => 021354987
[FCS_USAGE_CODE] => R
[FCS_TYPE_OF_SERVICE] =>
[COMPANY_NAME] =>
)
)
[Credit] => Array
(
[Total] => 88266
)
)
)Notice it drops the numbering on the array. This is my problem, without this number it goes screwy and the results are all garbled.
What I am trying to do is create a bit of code that loads a different table content if the array isn't numbered. And this is where I am very stuck as I can't find anything to tell the script that "if this value is nothing, then load this code"... sorry if this is confusing, Im not too good with terminology. Below is the script I'm using. <?php
/*
* $Id: wsdlclient1.php,v 1.2 2004/03/15 23:06:17 snichol Exp $
*
* WSDL client sample.
*
* Service: WSDL
* Payload: document/literal
* Transport: http
* Authentication: none
*/
require_once('../nusoap-0.7.2/lib/nusoap.php'); // Tony's path
//require_once('../lib/nusoap.php'); // Gabe's path
$proxyhost = isset($_POST['proxyhost']) ? $_POST['proxyhost'] : '';
$proxyport = isset($_POST['proxyport']) ? $_POST['proxyport'] : '';
$proxyusername = isset($_POST['proxyusername']) ? $_POST['proxyusername'] : '';
$proxypassword = isset($_POST['proxypassword']) ? $_POST['proxypassword'] : '';
$client = new soapclient('http://search.fcsonline.com.au/FCSSearchWS/FCSSearch.asmx?WSDL', true,
$proxyhost, $proxyport, $proxyusername, $proxypassword);
$fcsuser = '';
$fcspass = '';
//$fcsuser = $_GET['user'];
//$fcspass = $_GET['pass'];
$auth="<AuthHeader xmlns=\"http://202.125.163.83/FCSSearchWS/FCSSearch.asmx\"><UserName>$fcsuser</UserName><Password>$fcspass</Password></AuthHeader>";
$client->setHeaders($auth);
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
// Doc/lit parameters get wrapped
$strPin = $_GET['pin'];
$strName1 = '';
$strName2 = $_GET['name2'];
$strName3 = $_GET['name3'];
$strSurname = 'Brisciani';
$strUnit = $_GET['unit'];
$strNumLow = $_GET['numlow'];
$strNumHigh = $_GET['numhigh'];
$strStreet = $_GET['street'];
$strSuburb = $_GET['suburb'];
$strState = $_GET['state'];
$strPostcode = $_GET['postcode'];
$strBuildname = $_GET['buildname'];
$strPObox = $_GET['pobox'];
$strReference = $_GET['ref'];
$param = array( 'PIN' => $strPin,
'GivenName1' => $strName1,
'GivenName2' => $strName2,
'GivenName3' => $strName3,
'Surname' => $strSurname,
'UnitNumber' => $strUnit,
'StreetNumberLow' => $strNumLow,
'StreetNumberHigh' => $strNumHigh,
'StreetName' => $strStreet,
'Suburb' => $strSuburb,
'State' => $strState,
'Postcode' => $strPostcode,
'BuildingName' => $strBuildname,
'POBox' => $strPObox,
'ClientRef' => $strReference
);
$result = $client->call('PhoneSearch', array('parameters' => $param), '', '', false, true);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
/***
echo "<pre>"; //You can uncomment this stuff to get a look at the returned array
print_r($result);
echo "</pre>";
***/
//We can work our way down through the $result to get what we need:
$PhoneSearchResult = $result['PhoneSearchResult'];
$Phone = $PhoneSearchResult['Phone'];
$PhoneItem = $Phone['PhoneItem']; // <-- That's the one we want to loop through
//Set up our array to hold the post codes
$pCodes = array();
// $pCodeCount = 0;
echo "<table border=\"1\">";
echo "<tr><th>Surname</th><th>Given Name</th><th>Address</th><th>Suburb</th><th>State</th><th>Post Code</th><th>Phone</th></tr>";
foreach($Phone as &$item){
echo "<tr>";
echo "<td>single";
echo $item['SURNAME'];
echo "</td>";
echo "<td>";
echo $item['GIVEN_NAME_1'];
echo "</td>";
echo "<td>";
echo $item['AD1'];
echo "</td>";
echo "<td>";
echo $item['LOC'];
echo "</td>";
echo "<td>";
echo $item['STT'];
echo "</td>";
echo "<td>";
echo $item['PCD'];
echo "</td>";
echo "<td>";
echo $item['PUBLIC_NUMBER'];
echo "</td>";
echo "</tr>";
}
if ($somthing='0') { //THIS IS WHERE I'M STUCK
foreach($PhoneItem as &$item){
echo "<tr>";
echo "<td>1";
echo $item['SURNAME'];
echo "</td>";
echo "<td>";
echo $item['GIVEN_NAME_1'];
echo "</td>";
echo "<td>";
echo $item['AD1'];
echo "</td>";
echo "<td>";
echo $item['LOC'];
echo "</td>";
echo "<td>";
echo $item['STT'];
echo "</td>";
echo "<td>";
echo $item['PCD'];
echo "</td>";
echo "<td>";
echo $item['PUBLIC_NUMBER'];
echo "</td>";
echo "</tr>";
}
}
echo "</table>";
}
}
//echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
//echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
//echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>