我正在嘗試從phpmyadmin數據庫中檢索特定值。我想要從mytasksend表中檢索to=$username
所在的行。 但是,當我回顯變量我沒有得到任何輸出。 我該怎麼做?爲什麼我無法從android獲得php的值?
這是我的PHP文件
<?php
mysql_connect ("localhost","root","");
mysql_select_db("taskmanager");
$username= (isset($_POST['to'])) ? $_POST['to'] : '';
$q=mysql_query("SELECT `tasksentid` FROM `mytasksend` where `to` = $username") or die(mysql_error());
$output=array();
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print (json_encode($output));
mysql_close();
?>
,這裏是我的Java文件
try{
HttpClient httpclient3 = new DefaultHttpClient();
HttpPost httppost3 = new HttpPost("http://10.0.2.2:80/selection.php");
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("to",id));
Log.w("aaaaaaa",""+nameValuePairs);
httppost3.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient3.execute(httppost3);
HttpEntity entity = response.getEntity();
is = entity.getContent();
Log.e("log_tag", "connection success ");
}
來傳遞謝謝..工作 – user3256145