Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --php code--
- <?
- $response = array();
- $dsn='sqlserver';
- $username='street';
- $password='keymaker';
- $koneksi= odbc_connect($dsn,$username,$password);
- $query = "SELECT * FROM Vw_ATM";
- $result = odbc_exec($koneksi, $query);
- if (odbc_num_rows($result) > 0) {
- $response["Vw_ATM"] = array();
- while ($row = odbc_fetch_array($result)) {
- $Vw_ATM = array();
- $Vw_ATM["Fk_Merchant_ID"] = $row["Fk_Merchant_ID"];
- $Vw_ATM["Name"] = $row["Name"];
- $Vw_ATM["Address"] = $row["Address"];
- $Vw_ATM["Longitude"] = $row["Longitude"];
- $Vw_ATM["Latitude"] = $row["Latitude"];
- array_push($response["Vw_ATM"], $Vw_ATM);
- }
- $response["success"] = 1;
- echo json_encode($response);
- } else {
- $response["success"] = 0;
- $response["message"] = "No Data";
- echo json_encode($response);
- }
- odbc_close($koneksi);
- ?>
- --android code--
- @Override
- protected String doInBackground(String... arg0) {
- List<NameValuePair> params = new ArrayList<NameValuePair>();
- JSONObject json = jParser.makeHttpRequest(url_, "GET", params);
- Log.d("Get List :", json.toString());
- try {
- int success = json.getInt(TAG_SUCCESS);
- if (success == 1) {
- data = json.getJSONArray(TAG_DATA);
- for (int i=0; i<data.length(); i++) {
- JSONObject c = data.getJSONObject(i);
- String id = c.getString(TAG_ID);
- String name = c.getString(TAG_NAME);
- HashMap<String, String> map = new HashMap<String, String>();
- map.put(TAG_ID, id);
- map.put(TAG_NAME, name);
- dataList.add(map);
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- }
- return null;
- }
Add Comment
Please, Sign In to add comment