Guest User

Untitled

a guest
Feb 11th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. --php code--
  2. <?
  3. $response = array();
  4. $dsn='sqlserver';
  5. $username='street';
  6. $password='keymaker';
  7. $koneksi= odbc_connect($dsn,$username,$password);
  8. $query = "SELECT * FROM Vw_ATM";
  9. $result = odbc_exec($koneksi, $query);
  10. if (odbc_num_rows($result) > 0) {
  11. $response["Vw_ATM"] = array();
  12. while ($row = odbc_fetch_array($result)) {
  13. $Vw_ATM = array();
  14. $Vw_ATM["Fk_Merchant_ID"] = $row["Fk_Merchant_ID"];
  15. $Vw_ATM["Name"] = $row["Name"];
  16. $Vw_ATM["Address"] = $row["Address"];
  17. $Vw_ATM["Longitude"] = $row["Longitude"];
  18. $Vw_ATM["Latitude"] = $row["Latitude"];
  19. array_push($response["Vw_ATM"], $Vw_ATM);
  20. }
  21.  
  22. $response["success"] = 1;
  23. echo json_encode($response);
  24. } else {
  25.  
  26. $response["success"] = 0;
  27. $response["message"] = "No Data";
  28.  
  29. echo json_encode($response);
  30. }
  31. odbc_close($koneksi);
  32. ?>
  33. --android code--
  34. @Override
  35. protected String doInBackground(String... arg0) {
  36. List<NameValuePair> params = new ArrayList<NameValuePair>();
  37. JSONObject json = jParser.makeHttpRequest(url_, "GET", params);
  38. Log.d("Get List :", json.toString());
  39. try {
  40. int success = json.getInt(TAG_SUCCESS);
  41. if (success == 1) {
  42. data = json.getJSONArray(TAG_DATA);
  43. for (int i=0; i<data.length(); i++) {
  44. JSONObject c = data.getJSONObject(i);
  45. String id = c.getString(TAG_ID);
  46. String name = c.getString(TAG_NAME);
  47. HashMap<String, String> map = new HashMap<String, String>();
  48. map.put(TAG_ID, id);
  49. map.put(TAG_NAME, name);
  50. dataList.add(map);
  51. }
  52. }
  53. } catch (Exception e) {
  54. // TODO: handle exception
  55. e.printStackTrace();
  56. }
  57. return null;
  58. }
Add Comment
Please, Sign In to add comment