2013-02-08 66 views
-1

我面臨將值傳遞給Android的PHP腳本的問題。如何將值從android傳遞到php?

我想要questionid傳遞到php腳本url_get_ansurl但我不能傳遞值。

如何做到這一點?請指導我。

非常感謝。

try { 
     int success = json.getInt(TAG_SUCCESS); 
     if (success == 1) { 
      System.out.println("Success"); 
      groups = json.getJSONArray(TAG_GROUP); 
      System.out.println("Result Success+++"+groups); 
      for (int i = 0; i < groups.length();i++) { 
      JSONObject c = groups.getJSONObject(i); 
      String question = c.getString(TAG_QUES); 
      System.out.println("Checking ::"+question); 
      ques1.add(question); 
      String questionid = c.getString(TAG_QUESID); 
      System.out.println("Checking ::"+questionid); 
      id=questionid; 
      quesid.add(questionid); 
      } 
     } else { 
      showAlert(); 
     } 
    } catch (JSONException e) { 
     System.out.println("Error "+e.toString()); 
    } 
     List<NameValuePair> params1 = new ArrayList<NameValuePair>(); 
     params1.add(new BasicNameValuePair("qid", qid)); 
     json = jsonParser.makeHttpRequest(url_get_ansurl, "GET", params1); 
     System.out.println("ques value got"); 
     Log.d("All Groups: ", json.toString()); 
     System.out.println("question"); 
     try { 
     int success = json.getInt(TAG_SUCCESS); 
     System.out.println("Success"); 
     if (success == 1) { 
      System.out.println("Success"); 
      groups = json.getJSONArray(TAG_GROUP); 
      System.out.println("Result Success+++"+groups); 
      for (int i = 0; i < groups.length();i++) { 
      JSONObject c = groups.getJSONObject(i); 
       String answer = c.getString(TAG_ANSW); 
       System.out.println("Checking ::"+answer); 
       answ1.add(answer); 
      } 
     } else { 
      showAlert(); 
     } 
    } catch (JSONException e) { 
     System.out.println("Error "+e.toString()); 
    } 
    protected void onPostExecute(String file_url) { 
     pDialog.dismiss(); 
    ques1=new ArrayList<String>(new ArrayList<String>(ques1)); 
     // j=0; 
     TextView txtque = (TextView) findViewById(R.id.que_txt); 
     txtque.setText(ques1.get(j)); 
+0

其中'questionid'ü要在PHP中要發送的文件? –

+0

字符串questionid或quesid ..但quesid是陣列..我想當第一個問題顯示第一個問號我想發送到PHP ... –

+0

@dilix請指導我..如何做到這一點? –

回答

2

您可以通過POST使用或GET

List<NameValuePair> params = new ArrayList<NameValuePair>(); 
    params.add(new BasicNameValuePair("questionid", questionid)); 

    try { 
     HttpParams httpParameters = new BasicHttpParams(); 
     HttpConnectionParams.setConnectionTimeout(httpParameters, 10000); 
     HttpConnectionParams.setSoTimeout(httpParameters, 10000); 
     HttpClient httpClientpost = new DefaultHttpClient(httpParameters); 

     //HttpGet post = new HttpGet(url_request); 
     HttpPost post = new HttpPost(url_request); 

     UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params, 
       HTTP.UTF_8); 
     post.setEntity(ent); 


     HttpResponse responsePOST = httpClientpost.execute(post); 
     HttpEntity resEntity = responsePOST.getEntity(); 
     String getresponse = EntityUtils.toString(resEntity); //Response from the server 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } catch (JSONException e) { 
     e.printStackTrace(); 
    } 
+0

不,不sqlite數據庫即時通訊使用MySQL數據庫... –

+0

這是mysql,'url_request'是你的服務器的URL你想POST或GET – NaviRamyle

+0

請指導我使用json。 –