php-无法通过给定ID从MySQL检索到android listView的数据
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php-无法通过给定ID从MySQL检索到android listView的数据,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3500字,纯文字阅读大概需要6分钟。
内容图文
![php-无法通过给定ID从MySQL检索到android listView的数据](/upload/InfoBanner/zyjiaocheng/885/6216d25354494ff3809774032ab9863c.jpg)
我有一个表格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的数据所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。