How To Create Json Response
I am developing an android app by using google map v2, at server end i am using php and mysql database. In database there are already many location coordinates in terms of latitude
Solution 1:
Try mysql_fetch_assoc:
$json = array();
while ($row = mysql_fetch_assoc($result)) {
$json[$row['uid']] = array(
'lat' => $row['lat'],
'lon' => $row['lon'],
'loc' => $row['loc']
);
}
echo json_encode($json);
You should use MySQLi or PDO_MySQL instead of mysql_.
Solution 2:
You can use like this:
$result = mysql_query("SELECT uid, lat, long, loc FROM table")
$user = array();
$i=0;
foreach($resultas$key => $val){
$mess[$i][uid]=$val[uid];
$mess[$i][uid]=$val[lat];
$mess[$i][uid]=$val[long];
$i++;
}
$user=$mess;
echo json_encode($user);
I hope this will help you.
Solution 3:
You can take your $results and build it out to an array then pass it through the json_encode as follows..
json_encode($array);
You would do this in php to output json
Post a Comment for "How To Create Json Response"