|
|
|
PHP สอบถามการส่งข้อมูลใน Web Service ให้ได้มากกว่า 1 ค่า |
|
|
|
|
|
|
|
จากบทความนี้ครับ การรับส่งค่า Result ผ่านเว็บเซอร์วิส (NuSoap)
https://www.thaicreate.com/community/php-web-service-mysql.html
ผมทำการส่งค่าตามที่บทความนี้แนะนำได้แล้วครับแต่ผมต้องการส่งค่ามากกว่า 1 ค่า เพื่อไปค้นหาข้อมูลสมาชิกครับ
ตอนนี้ code ที่ผมทำ
WebServiceServer.php
Code (PHP)
<?
require_once("lib/nusoap.php");
//Create a new soap server
$server = new soap_server();
//Define our namespace
$namespace = "http://localhost/WebServiceServer.php";
$server->wsdl->schemaTargetNamespace = $namespace;
//Configure our WSDL
$server->configureWSDL("getCustomer");
//Add ComplexType
$server->wsdl->addComplexType(
'DataList',
'complexType',
'struct',
'all',
'',
array(
'user' => array('name' => 'user', 'type' => 'xsd:string'),
'password' => array('name' => 'password', 'type' => 'xsd:string')
)
);
//Add ComplexType
$server->wsdl->addComplexType(
'DataListResult',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:DataList[]')
),
'tns:DataList'
);
//Register our method and argument parameters
$varname = array(
'strCountry' => "xsd:string",
'strPass' => "xsd:string"
);
// Register service and method
$server->register('resultCustomer', // method name
$varname, // input parameters
array('return' => 'tns:DataListResult'));
function resultCustomer($strCountry,$strPass)
{
$objConnect = mysql_connect("localhost","admin","") or die(mysql_error());
$objDB = mysql_select_db("admin")or die(mysql_error());
$strSQL = "SELECT * FROM userpwd WHERE user = '".$strCountry."' AND password = '".$strPass."' ";
//$strSQL = "SELECT * FROM userpwd";
$objQuery = mysql_query($strSQL) or die (mysql_error());
$intNumField = mysql_num_fields($objQuery);
$resultArray = array();
while($obResult = mysql_fetch_array($objQuery))
{
$arrCol = array();
for($i=0;$i<$intNumField;$i++)
{
$arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
}
array_push($resultArray,$arrCol);
}
mysql_close($objConnect);
return $resultArray;
}
// Get our posted data if the service is being consumed
// otherwise leave this data blank.
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
// pass our posted data (or nothing) to the soap service
$server->service($POST_DATA);
exit();
?>
WebServiceClient.php
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=TIS-620">
<title>ThaiCreate.Com</title>
</head>
<body>
<form name="frmMain" method="post" action="">
<h2>Search Customer</h2>
Search by Country Code
<input type="text" name="txtCountry" value="<?=$_POST["txtCountry"];?>">
<input type="text" name="txtCountry" value="<?=$_POST["txtPass"];?>">
<input type="submit" name="Submit" value="Submit">
</form>
<?
if($_POST["txtCountry"] != "")
{
include("lib/nusoap.php");
$client = new nusoap_client("http://localhost/WebServiceServer.php?wsdl",true);
$params = array(
'strCountry' => $_POST["txtCountry"],
'strPass' => $_POST["txtPass"]
);
$data = $client->call('resultCustomer', $params);
//echo '<pre>';
//var_dump($data);
//echo '</pre><hr />';
if(count($data) == 0)
{
echo "Not found data!";
echo "<script type='text/javascript'>alert('1')</script>";
}
else
{
echo "<script type='text/javascript'>alert('2')</script>";
echo '<pre>';
var_dump($data);
echo '</pre><hr />';
?>
<table width="500" border="1">
<tr>
<td>CustomerID</td>
<td>Name</td>
</tr>
<?
foreach ($data as $result)
{
?>
<tr>
<td><?=$result["user"];?></td>
<td><?=$result["password"];?></td>
</tr>
<?
}
?>
</table>
<?
}
}
?>
</body>
</html>
Tag : PHP
|
|
|
|
|
|
Date :
2012-06-12 11:20:31 |
By :
vissarud |
View :
1228 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วครับ พลาดตรงที่ mr.win แนะนำไว้ครับ
ขอบคุณครับ mr.win
|
|
|
|
|
Date :
2012-06-12 11:46:18 |
By :
vissarud |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับ mr.win
|
|
|
|
|
Date :
2012-06-13 11:08:29 |
By :
vissarud |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|