日期:2014-05-16 浏览次数:20568 次
CREATE TABLE `people` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `name` VARCHAR( 100 ) NOT NULL , `sex` BOOL NOT NULL DEFAULT '1', `birthyear` INT NOT NULL )
'".$_REQUEST['year']."'");
while($e=mysql_fetch_assoc($q))
        $output[]=$e;
print(json_encode($output));
mysql_close();
?>String result = "";
//the year data to send
ArrayList nameValuePairs = new
ArrayList();
nameValuePairs.add(new BasicNameValuePair("year","1980"));
//http post
try{
        HttpClient httpclient = new DefaultHttpClient();
 HttpPost httppost = new
HttpPost("http://example.com/getAllPeopleBornAfter.php");
   httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        InputStream is = entity.getContent();
}catch(Exception e){
        Log.e("log_tag", "Error in http connection "+e.toString());
}
//convert response to string
try{
        BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
        }
        is.close();
        result=sb.toString();
}catch(Exception e){
        Log.e("log_tag", "Error converting result "+e.toString());
}
//parse json data
try{
        JSONArray jArray = new JSONArray(result);
        for(int i=0;i