php-无法通过给定ID从MySQL检索到android listView的数据

php-无法通过给定ID从MySQL检索到android listView的数据,第1张

概述我有一个表格workDetails,如下图所示.现在,我想检索twd等于1的两个数据,并将它们加载到androidlistView中.我不确定我错过了什么,因为没有检索到数据.publicvoidBuildEditDetails(finalStringID){//Itholds1classGetDataJSONextendsAsyncTask<String,

我有一个表格workDetails,如下图所示.

现在,我想检索twd等于1的两个数据,并将它们加载到androID ListVIEw中.我不确定我错过了什么,因为没有检索到数据.

  public voID BuildEditDetails(final String ID) { // It holds 1        class GetDataJsON extends AsyncTask<String, VoID, String> {            @OverrIDe            protected String doInBackground(String... params) {                DefaulthttpClIEnt httpclIEnt = new DefaulthttpClIEnt(new BasichttpParams());                httpPost httppost = new httpPost("http://192.168.1.7/AndroID/CRUD/detailsRetrIEve.PHP?ID="+ID);                // Depends on your web service                httppost.setheader("Content-type", "application/Json");                inputStream inputStream = null;                String result = null;                try {                    httpResponse response = httpclIEnt.execute(httppost);                    httpentity entity = response.getEntity();                    inputStream = entity.getContent();                    // Json is UTF-8 by default                    BufferedReader reader = new BufferedReader(new inputStreamReader(inputStream, "UTF-8"), 8);                    StringBuilder sb = new StringBuilder();                    String line = null;                    while ((line = reader.readline()) != null)                    {                        sb.append(line + "\n");                    }                    result = sb.toString();                } catch (Exception e) {                    // Oops                }                finally {                    try{if(inputStream != null)inputStream.close();}catch(Exception squish){}                }                return result;            }            @OverrIDe            protected voID onPostExecute(String result){                myJsON=result;                showList();            }        }        GetDataJsON g = new GetDataJsON();        g.execute();    }    protected voID showList(){        try {            JsONObject JsonObj = new JsONObject(myJsON);            details= JsonObj.getJsONArray(Config.TAG_RESulTS);            for(int i=0;i<details.length();i++){                JsONObject c = details.getJsONObject(i);                String project = c.getString(Config.TAG_PROJECT);                String description = c.getString(Config.TAG_WORKDESCRIPTION);                int percentage = c.getInt(Config.TAG_PERCENTAGE);                String in=c.getString(Config.TAG_IN);                String out=c.getString(Config.TAG_OUT);                int ID=c.getInt(Config.TAG_ID);                HashMap<String,String> info = new HashMap<String,String>();                info.put(Config.TAG_PROJECT, project);                info.put(Config.TAG_WORKDESCRIPTION, description);                info.put(Config.TAG_PERCENTAGE,percentage+"");                info.put(Config.TAG_IN,in);                info.put(Config.TAG_OUT,out);                info.put(Config.TAG_ID,ID+"");                EditDetails.add(info);            }            listadapter adapter = new SimpleAdapter(                    getActivity(),EditDetails, R.layout.retrIEve_details,                    new String[]{Config.TAG_PROJECT,Config.TAG_WORKDESCRIPTION,Config.TAG_PERCENTAGE,Config.TAG_IN,Config.TAG_OUT},                    new int[]{R.ID.Project,R.ID.Description,R.ID.in, R.ID.out,R.ID.Percentage}            );            ListVIEwUpdate.setAdapter(adapter);        } catch (JsONException e) {            e.printstacktrace();        }    }

详细信息

<?PHP   define('HOST','127.0.0.1:3307');   define('USER','root');   define('PASS','');   define('DB','androIDdb');   $con = MysqLi_connect(HOST,USER,PASS,DB) or dIE('unable to connect');   $ID=$_GET['ID'];   $sql = "select * from work_details WHERE twd= '". $ID."'";   $res = MysqLi_query($con,$sql);   $result=array();   while($row=MysqLi_fetch_array($res)){       array_push($result,array('ID'=>$row[0],'project'=>$row[1],'work_description'=>$row[2],'percentage'=>$row[3],'timeIn'=>$row[4],      'timeOut'=>$row[5], 'twd'=>$row[6]));   }   echo (Json_encode(array("result"=>$result)));   MysqLi_close($con);?>

设定档

public static final String TAG_RESulTS="result";public static final String TAG_ID = "ID";public static final String TAG_PROJECT="project";public static final String TAG_WORKDESCRIPTION="work_description";public static final String TAG_PERCENTAGE="percentage";public static final String TAG_IN="timeIn";public static final String TAG_OUT="timeOut";

解决方法:

您的$ID = $_GET [“ ID”]错误.尝试将其更改为$ID = $_ GET [“ ID”].您正在从detailsRetrIEve检索,但是您的文件是detailsRetrIEved.忽略是否​​仅是印刷错误.

总结

以上是内存溢出为你收集整理的php-无法通过给定ID从MySQL检索到android listView的数据全部内容,希望文章能够帮你解决php-无法通过给定ID从MySQL检索到android listView的数据所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1090307.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存