2011-05-19 27 views
0

我有一個應用程序讀取一個MySQL數據庫如下所示Android應用讀取經由PHP服務MySQL數據庫

<?php 
mysql_connect("host","username","password"); 
mysql_select_db("Cars"); 

$q=mysql_query("SELECT * FROM car WHERE model_year>'".$_REQUEST['year']."'"); 
while($e=mysql_fetch_assoc($q)) 
     $output[]=$e; 

print(json_encode($output)); 

mysql_close(); 
?> 

並且被如下所示

該發送請求和讀出的數據的java的機器人代碼
String result = ""; 
//the year data to send 
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 
nameValuePairs.add(new BasicNameValuePair("year","1998")); 

//http post 
try{ 
     HttpClient httpclient = new DefaultHttpClient(); 
     HttpPost httppost = new HttpPost("http://example.com/getmodelsafter.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()); 
} 

然後捕獲數據。

應該如何在情況下,我想通過拖不同的價值觀在我的數據庫可以說

<?php 
mysql_connect("host","username","password"); 
mysql_select_db("Cars"); 

$q=mysql_query("SELECT * FROM car WHERE model_year>'".$_REQUEST['year']."' 
and color="'".$_REQUEST['color']."'"); 
while($e=mysql_fetch_assoc($q)) 
     $output[]=$e; 

print(json_encode($output)); 

mysql_close(); 
?> 

回答