java - How to display only selected data from database in Android Studio -
my program designed search database specific name entered, program display row of specific name. however, code unable display specific data. have tried many kind of ways unable solve problem. php code below:
<?php $con = mysql_connect('mysql17.000webhost.com', 'a2634311_minzhe', 'mzrules0118'); if (!$con) { die('could not connect: ' . mysql_error()); } mysql_select_db("a2634311_gdp", $con); $result = mysql_query("select * groupdesign"); while($row = mysql_fetch_assoc($result)) { $output[]=$row; } print(json_encode($output)); mysql_close($con); ?>
my activity code below:
import android.app.activity; import android.content.context; import android.content.intent; import android.content.sharedpreferences; import android.os.asynctask; import android.os.strictmode; import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.util.log; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.baseadapter; import android.widget.button; import android.widget.listview; import android.widget.textview; import android.widget.toast; import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject; import java.io.inputstream; public class patientlocation extends actionbaractivity { private listview patientlocationlistview; @override protected void oncreate(bundle savedinstancestate) { strictmode.threadpolicy policy = new strictmode.threadpolicy.builder().permitall().build(); strictmode.setthreadpolicy(policy); this.patientlocationlistview = (listview) this.findviewbyid(r.id.listview4); new location().execute(new api_connector()); } public void setlistadapter(jsonarray jsonarray) { sharedpreferences settings = getsharedpreferences("myprefrences", context.mode_private); string name = settings.getstring("name", ""); this.patientlocationlistview.setadapter(new patientadapter(jsonarray,name, this)); } private class location extends asynctask<api_connector, long, jsonarray> { @override protected jsonarray doinbackground(api_connector... params) { //it executed on background thread return params[0].getpatientlocation(); } @override protected void onpostexecute(jsonarray jsonarray) { // check null if (jsonarray != null) { // pass array adapter if not null setlistadapter(jsonarray); } else { toast.maketext(patientlocation.this, "null array returned", toast.length_short).show(); } } } } class patientadapter extends baseadapter { private jsonarray dataarray; private activity activity; string pname; private static layoutinflater inflater = null; public patientadapter(jsonarray jsonarray, string name, activity a) { this.dataarray = jsonarray; this.activity = a; this.pname = name; inflater = (layoutinflater) this.activity.getsystemservice(context.layout_inflater_service); } @override public int getcount() { return this.dataarray.length(); } @override public object getitem(int position) { return position; } @override public long getitemid(int position) { return position; } @override public view getview(int position, view convertview, viewgroup parent) { string patientname,patientlocation; //set convert view if null listcell cell = new listcell(); if (convertview == null) { convertview = inflater.inflate(r.layout.activity_position, null); cell.patient_name = (textview) convertview.findviewbyid(r.id.textview30); cell.patient_location = (textview) convertview.findviewbyid(r.id.textview31); convertview.settag(cell); } else { cell = (listcell) convertview.gettag(); } //change data of cell try { for(int i=0;i<dataarray.length();i++) { jsonobject jsonobject = this.dataarray.getjsonobject(i); if(pname == jsonobject.getstring("name")) { patientname = jsonobject.getstring("name"); patientlocation = jsonobject.getstring("location"); cell.patient_name.settext(patientname); cell.patient_location.settext(patientlocation); } } } catch (jsonexception e) { e.printstacktrace(); } return convertview; } private class listcell { private textview patient_name; private textview patient_location; } }
where clause in query in php code? need set conditions match specific name in query if want search 'abcd' query should select * groupdesign column_name = "abcd"
. return records contanis value "abcd" database
Comments
Post a Comment