试图让我的PHP脚本返回一些SQL表查询。这里是我的脚本,因为它代表现在:我的PHP正在返回错误信息?
<?php
define("DB_HOST", "localhost");
define("DB_USER", "*");
define("DB_PASSWORD", "*");
define("DB_DATABASE", "*");
mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_DATABASE);
if (isset($_POST['tag']) && $_POST['tag'] != '') {
$tag = $_POST['tag'];
echo $tag;
if ($tag == 'question') {
$category = $_POST['category'];
$response=mysql_query("select * from QUESTIONS where CATEGORY like '$category'");
return $category; //just doing this, rather than $response to see if it works
}
}
?>
这里还有一个与此相关的Android的代码:
public JSONObject getQuestionsJSONFromUrl(String url, List<NameValuePair> params) {
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
Log.v("while", line);
sb.append(line + "\n");
//Log.v("err", line);
}
is.close();
以及调用getQuestionsJSON方法...:
private static String question_tag = "question";
public JSONObject getQuestions(String category) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("tag", question_tag));
params.add(new BasicNameValuePair("category", category));
//JSONObject json;
JSONObject questionsList = jsonParser.getQuestionsJSONFromUrl(questionURL, params);
//return json
return null;
}
这里是Log.v()的LogCat,我在getQuestionsJSON ...()方法中有:
04-04 20:41:58.721: V/while(933): question
所以我真的不明白为什么这是返回'问题',而不是我运行getQuestions()时传递的字符串?
回声$标签;回复你的'问题' – marcinj 2012-04-04 21:01:17