I have some problems getting data from local server to Android Application. The architecture: Android - PHP/Query - MySQL database.
This is the function (in loadData.php) calling the function (in db_function.php) which does the query:
$exists = $db -> loadData($id);
In db_function.php the function looks like this:
public function loadData($app_cust_id) {
$results = mysql_query("SELECT * FROM ...") or die (mysql_error());
$messages = array();
if (mysql_num_rows($results)) {
while ($result = mysql_fetch_assoc($results)) {
$messages[] = $result;
}
}
return $messages;
...and now back...What do i have to write in order to get array result back and echo the right json_encode? Do i have to create a new array, loop through result and store it in the new array?
$result = $db -> loadData($id);
// ???
$response["success"] = 0;
echo json_encode($response);
EDIT :
$result = $db -> loadData($id);
$result["success"] = 0;
echo json_encode($result);
So i did these changes. It seems like no data is sended back to my java function. The logcat says: "Error parsing data org.json.JSONException: End of input at character 0 of" I didn´t find a solution. Anyone who can tell me about handling with the right json_encode and the right jsonparser in java. thanks a lot!
JSONObject json = jsonParser.getJSONFromUrl(URL, params);;