I am currently following a tutorial on retrieving data utilizing an online sql database, volley and android. How ever i am having real trouble making it so that more than one item is displayed. It only displays 1 row of the table even if 5 records match. Any help on this would be much appreciated
I added a loop to the php, which does work if i go through the url. exampleurl/id="1" displays all correct records in the browser. but im stuck on the java side as it only displays one item
while($res = mysqli_fetch_array($r)){
$result = array();
You are using the same TextView to override again and again the data:
textViewResult.setText("Name:\t"+name+"
Address:\t" +address+ "
Vice Chancellor:\t"+ vc);
Why don't you use a ListView to show all your results?
You should use Listview or spinner based on your requirement to show more than one item.
JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY);
after the the above code simply use
JSONObject collegeData;
for(int i = 0; i<result.length(); i++){
collegeData = result.getJSONObject(i);
name = collegeData.getString(Config.KEY_NAME);
address = collegeData.getString(Config.KEY_ADDRESS);
vc = collegeData.getString(Config.KEY_VC);
// populate logic here for your spinner or list
}
Edit
Initialize below
ArrayAdapter adapter;
private ArrayList<String> dataList = new ArrayList<>();
in onCreate() declare the adapter and your ListView
ListView listView = (ListView) findViewById(R.id.your_list_view_id);
adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, dataList);
Now replace "//populate logic here for your spinner or list" with
dataList.add(name + " " + address + " " vc);
After for loop add these line
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
Do this and let me know the output. Of course I didn't check this code but it should do the work. Good luck.