无法将spinner值android传递给php

时间:2014-08-04 08:05:01

标签: php android

我需要从包含数百个项目的外部数据库中读取数据。所以我试图将微调器选择值传递给php

机器人:

protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.icd);
states = getResources().getStringArray(R.array.Diseases);
t1 = (TextView) findViewById(R.id.textView1);

spinner = (Spinner) findViewById(R.id.country_spinner);

ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
        android.R.layout.simple_spinner_item, states);
dataAdapter
        .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter);

spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

    @Override
    public void onItemSelected(AdapterView<?> parent, View view,
            int position, long id) {

        ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();

        value = spinner.getSelectedItem().toString();

        // define the parameter
        postParameters.add(new BasicNameValuePair("789", value));
        try {
            CustomHttpClient.executeHttpGet("789");
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

php代码:

if(isset($_POST['789'])){
$id = $_POST['789']; 
$sql = "SELECT icd_symptoms FROM icd WHERE icd_disease = 'id'";
$result = mysql_query($sql);
while($row=mysql_fetch_assoc($result))
$output[]=$row;
print(json_encode($output));
mysql_close(); 

如何将数据从spinner android传递给php查询,以便查询只返回选定值的正确项目

1 个答案:

答案 0 :(得分:0)

CustomHttpClient.executeHttpGet("789");应该返回您查询的结果,之后您可以对结果做任何事情。