I am reading a php response in an android method.
PHP
if(mysqli_num_rows($result)>0) {
$status = "Success!";
echo "Success!";
} else {
echo "Login failed";
}
Android
@Override
protected void onPostExecute(String result) {
if(result.equals("Success!")) {
Toast.makeText(context, "Login Successful!", Toast.LENGTH_LONG).show();
Intent goToWelcomePage = new Intent(context, welcome.class);
context.startActivity(goToWelcomePage);
} else if (result.equals("User Created")){
Toast.makeText(context, "User Created. Login Now.", Toast.LENGTH_LONG).show();
Intent goToLoginPage = new Intent(context, MainActivity.class);
context.startActivity(goToLoginPage);
} else {
Toast.makeText(context, result, Toast.LENGTH_LONG).show();
}
}
The above script is working without any trouble.
However, I want to read an array of results.I tried this in PHP.
$status = array();
if(mysqli_num_rows($result)>0) {
$status = "Success!";
echo json_encode(array("result"=>$status,"name"=>$username));
} else {
$status = "Login failed";
echo json_encode(array("result"=>$status));
}
Not sure how to read this in Android. Besides, I am not sure if the above php is the right way to return results to android.