1. String result = "";
  2. //the year data to send
  3. ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
  4. nameValuePairs.add(new BasicNameValuePair("year","1980"));
  5.  
  6. //http post
  7. try{
  8.         HttpClient httpclient = new DefaultHttpClient();
  9.         HttpPost httppost = new HttpPost("http://example.com/getAl<wbr />lPeopleBornAfter.php");
  10.         httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  11.         HttpResponse response = httpclient.execute(httppost);
  12.         HttpEntity entity = response.getEntity();
  13.         InputStream is = entity.getContent();
  14. }catch(Exception e){
  15.         Log.e("log_tag", "Error in http connection "+e.toString());
  16. }
  17. //convert response to string
  18. try{
  19.         BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
  20.         StringBuilder sb = new StringBuilder();
  21.         String line = null;
  22.         while ((line = reader.readLine()) != null) {
  23.                 sb.append(line + "\n");
  24.         }
  25.         is.close();
  26.  
  27.         result=sb.toString();
  28. }catch(Exception e){
  29.         Log.e("log_tag", "Error converting result "+e.toString());
  30. }
  31.  
  32. //parse json data
  33. try{
  34.         JSONArray jArray = new JSONArray(result);
  35.         for(int i=0;i<jArray.length();i++){
  36.                 JSONObject json_data = jArray.getJSONObject(i);
  37.                 Log.i("log_tag","id: "+json_data.getInt("id")+
  38.                         ", name: "+json_data.getString("name")+
  39.                         ", sex: "+json_data.getInt("sex")+
  40.                         ", birthyear: "+json_data.getInt("birthyear")
  41.                 );
  42.         }
  43. }
  44. }catch(JSONException e){
  45.         Log.e("log_tag", "Error parsing data "+e.toString());
  46. }

 

 

 

http로 통신하는건 알겟는데 도통 로직을 모르겟네요;; ㅠㅠ

 

 

 

    <font face="굴림체"></font>
  1. <?php
  2. mysql_connect("host","username","password");
  3. mysql_select_db("PeopleData");
  4.  
  5. $q=mysql_query("SELECT * FROM people WHERE birthyear>'".$_REQUEST['year']."'");
  6. while($e=mysql_fetch_assoc($q))
  7.         $output[]=$e;
  8.  
  9. print(json_encode($output));
  10.  
  11. mysql_close();
  12. ?>

 

이건 php에서 쓰는거구요

 

 

mysql과 연동하는거 같은데 해석을 못하겟습니다. ㅜㅜ