I am new to android and I am stuck at one place. I wanted to fetch the date from mysql
database and display it in android app.
The code for android application
try {
JSONArray data = response.getJSONArray("std");
String result[]=new String[data.length()];
for (int i = 0; i < data.length(); i++)
{
JSONObject obj = data.getJSONObject(i);
name = obj.getString("Name");
fromdate=obj.getString("From");
todate = obj.getString("To");
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
Calendar cal=Calendar.getInstance();
Date fd=formatter.parse(fromdate);
cal.setTime(fd);
from1=cal.getTimeInMillis();
Date td=formatter.parse(todate);
cal.setTime(td);
to1=cal.getTimeInMillis();
date= DateUtils.formatDateRange( Main2Activity.this, from1, to1,
DateUtils.FORMAT_SHOW_YEAR );
result[i]=""+name+"\n"+date;
}
JSON FILE
<?php
$result=mysqli_query($link,"select * from oTrip");
$data=array();
$rows=mysqli_num_rows($result);
while($rec=mysqli_fetch_assoc($result))
{
$data[]=$rec;
}
header('Content-Type: application/json');
echo json_encode(array("std" =>$data));
?>
And the output is
Please help out with this!! Thank You.