|
|
|
Android ขอคำแนะนำเรื่องการรับค่า อาร์เรย์ จากเว็บเซอร์วิส พีเอชพีครับ (มีโค้ด) |
|
|
|
|
|
|
|
Code (PHP)
<?php
ob_start();
require_once("lib/nusoap.php");
$server = new soap_server();
$namespace = "http://localhost/IntelliCRMService/ws_profile.php";
//$server->wsdl->schemaTargetNamespace = $namespace;
$server->configureWSDL("Get_Profile");
$varname = array(
//'strrfid' => "xsd:string"
);
$server->register('Get_Profile', $varname, array('return' => 'xsd:string'));
function Get_Profile(){
$objDb= mysqli_connect("localhost", "tkoffice_demo", "DemoM3not", "tkoffice_demo");
if (!$objDb) {
printf("ERROR: Cannot connect to database! Please contact customer service.\n");
exit(1);
}
mysqli_query($objDb,"SET NAMES UTF8");
mysqli_query($objDb,"SET character_set_results=UTF8");
$strProfile = "SELECT * FROM crs_profiles order by profile_id ASC";
if (($objResult_Profile = mysqli_query($objDb,$strProfile)) != TRUE) {
printf("ERROR: Cannot read Profile!\n");
mysqli_close($objDb);
exit(1);
}
while ($row_profile = mysqli_fetch_array($objResult_Profile)) {
$profileTypeId = $row_profile["profile_type_id"];
$profileName = $row_profile["description"];
$strType = "SELECT * FROM crs_profile_types WHERE profile_type_id = '$profileTypeId'";
if (($objResult_Type = mysqli_query($objDb,$strType)) != TRUE) {
printf("ERROR: Cannot read Profile type!\n");
mysqli_close($objDb);
exit(1);
}
if ($row_type = mysqli_fetch_array($objResult_Type)) {
$typeName = $row_type["abbr"];
}
$arr['ProfileType'] = $typeName;
$arr['ProfileName'] = $profileName;
header('Content-type: application/json');
return json_encode($arr);
}
}
// 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();
?>
จากโค้ดด้านบนผมควรจะเขียนโค้ดรับค่ายังไงดีครับ คือที่ทำอยู่ตอนนี้รับค่าได้ครับ แต่มันค่าแรกในอาร์เรย์ค่าเดียว (แต่ข้อมูลในฐานข้อมูล มี 4)
ข้างล่างเป็นโค้ดที่ใช้อยู่ครับ
Code (Android-Java)
final String NAMESPACE = "http://demo.tkwebdesignthai.com/IntelliCRMService/ws_profile.php";
final String URL = "http://demo.tkwebdesignthai.com/IntelliCRMService/ws_profile.php?wsdl";
final String SOAP_ACTION = "http://demo.tkwebdesignthai.com/IntelliCRMService/ws_profile.php/Get_Profile";
final String METHOD_NAME = "Get_Profile";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidTransport = new HttpTransportSE(URL);
JSONObject c;
androidTransport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject)envelope.bodyIn;
for (int i = 0; i < result.getPropertyCount() ; i++){
c = new JSONObject(result.getProperty(i).toString());
PROFILENAME = c.getString("ProfileName");
PROFILETYPE = c.getString("ProfileType");
System.out.println(PROFILENAME);
System.out.println(PROFILETYPE);
}
} catch (IOException e) {
System.out.println("IO Error! : "+e);
//return null;
} catch (XmlPullParserException ex) {
System.out.println("XML Error! : "+ex);
//return null;
} catch (JSONException je) {
System.out.println("JSON Error! : "+je);
//return null;
}
Tag : Mobile, MySQL, Android
|
|
|
|
|
|
Date :
2015-04-24 15:52:36 |
By :
ideasza |
View :
1075 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เหมือนตัวนี้เลยครับ
Android and Web Server ของ PHP กับ MySQL แสดงบน ListView ในรูปแบบของ JSON
|
|
|
|
|
Date :
2015-04-24 17:31:01 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|