|
 |
|
ถามเรื่อง nusoap webservice อยากได้ ouptput แบบ ชื่อคนหนึ่งชื่อ แต่มีหลาย email หลาย address ต้องทำไงครับ |
|
 |
|
|
 |
 |
|
ผมได้เรียนรู้ การทำ webservice php ด้วย nusoap จาก web นี้แล้ว โอเคเลยครับ ได้ความรู้เยอะเลย
แต่โจทย์ของผมคือ output แบบนี้ครับ
ชื่อคน มี หลาย email มี หลาย address ผมต้องเขียนโปรแกรมยังไงละครับทีนี้ หรือมันไม่มีวิธีครับ ต้องใส่ array อันเดียวหมดหรือเปล่า?
ตัวอย่างที่ผมให้มาเป็น 1 คน ต่อ หลาย email นะครับ
Code (PHP)
Array
(
[0] => Array
(
[contact] => Chaos Captain
[email] => array(
[0] => ‘[email protected]’,
[1] => ‘[email protected]’,
[2] => ‘[email protected]’,
[3] => ‘[email protected]’,
),
)
[1] => Array
(
[contact] => Joe Joe
[email] => array(
[0] => ‘[email protected]’,
[1] => ‘[email protected]’,
[2] => ‘[email protected]’,
[3] => ‘[email protected]’,
),
)
)
Tag : PHP, CakePHP

|
|
 |
 |
 |
 |
Date :
2014-10-08 10:50:42 |
By :
AK |
View :
855 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
foreach(array[1]['email'] as $email){
echo $email;
}
|
ประวัติการแก้ไข 2014-10-08 11:13:57
 |
 |
 |
 |
Date :
2014-10-08 11:12:56 |
By :
gaowteen |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังครับคุณ BIrD ผมยังไม่ได้ output เลยครับ
ติดตั้งแต่สร้างเลยครับ สร้าง webservice ให้ออก output ทีว่า ไม่เป็นครับผม 
|
 |
 |
 |
 |
Date :
2014-10-08 11:33:21 |
By :
AK |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้คำตอบแล้วครับ
ผมดูตัวอย่างตาม web -> http://www.hirdweb.com/2010/08/05/modifying-the-nusoap-server/
ตัวอย่าง code ของผมครับ
$server->wsdl->addComplexType('surveyList','complexType','struct','all','',
array(
'code' => array('name' => 'code' , 'type' => 'xsd:string'),
'bu_type' => array ('name' => 'bu_type' , 'type' => 'xsd:string'),
'seq' => array ('name' => 'seq' , 'type' => 'xsd:int'),
'question_type' => array ('name' => 'question_type' , 'type' => 'xsd:string'),
'question' => array ('name' => 'question' , 'type' => 'xsd:string')
)
);
$server->wsdl->addComplexType('surveyLists','complexType','array','',
'SOAP-ENC:Array',
array(),
array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=> 'tns:surveyList[]')),'tns:surveyList'
);
$server->wsdl->addComplexType('surveyObj','complexType','struct','all','',
array(
'msg' => array('name' => 'msg', 'type' => 'xsd:string'),
'output' => array('name' => 'output' , 'type' => 'tns:surveyLists')
)
);
$input = array(
'email' => "xsd:string",
'password' => "xsd:string",
'bu_type' => "xsd:string"
);
$output = array('return' => 'tns:surveyObj');
$server->register('survey_list',$input, $output,$namespace);
function survey_list($email,$password,$bu_type){
/*
$resultArray['output'] = array(
array(
'code'=> 'test'
,'bu_type' => 'test'
,'seq' => 1
,'question_type' => 'test'
,'question' => 'tst'
),
array(
'code'=> 'test'
,'bu_type' => 'test'
,'seq' => 2
,'question_type' => 'test'
,'question' => 'tst'
)
);
$resultArray['msg'] = 'F';
return $resultArray;
*/
require_once("con_str.php");
$conn = mysql_connect($hostname,$hostuser,$hostpass);
if(!$conn)
die("not connect database!");
mysql_select_db($hostbase,$conn)
or die("not connect database");
mysql_query("SET NAMES UTF8");
$query = "select * from question where bu_type='" . $bu_type . "' ";
$result = mysql_query($query,$conn);
mysql_close($conn);
//$resultArray = array();
$numrow = mysql_num_rows($result);
$resultArray['msg'] = 'F';
$resultArray['output'] = array();
if($numrow > 0){
$resultArray['msg'] = 'T';
$outputArray = array();
$intNumField = mysql_num_fields($result);
while($obResult = mysql_fetch_array($result)){
$arrCol = array();
$arrCol['code'] = $obResult['code'];
$arrCol['bu_type'] = $obResult['bu_type'];
$arrCol['seq'] = $obResult['seq'];
$arrCol['question_type'] = $obResult['question_type'];
$arrCol['question'] = $obResult['question'];
array_push($outputArray,$arrCol);
}
$resultArray['output'] = $outputArray;
}
return $resultArray;
}
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
$server->service($POST_DATA);
หลักๆ มันมี obj 3 อันคือ
surveyLists -> เป็นตัวทำให้ surveyList เป็น array ตอนส่งออก output
surveyList -> โครงสร้างย่อย
surveyObj -> โครงสร้างหลัก ที่จะออก output
ถ้า output ที่ส่งออกไม่ได้เป็น array ให้ข้าม โครงสร้างแบบ surveyLists ได้เลยครับ ไปใช้ surveyList ก็พอครับ
เผื่อใครทำ webservice ด้วย nusoap แบบผมก็ เอาไปดูเป็นตัวอย่างได้นะครับ
ปล. ขอบคุณ คุณ BIrD นะครับที่ช่วย 
|
ประวัติการแก้ไข 2014-10-08 14:10:27
 |
 |
 |
 |
Date :
2014-10-08 14:08:49 |
By :
AK |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|