jeudi 25 janvier 2018

Laravel getting wrong data back to android from mysql database using volley Library

I hope you are okay, but me uhumm, my head is burning. I fetched data from mysql database to android using volley and Laravel. But now, when I execute the same app that was working before, now it's returning wrong data from database.

Where goes my code:

Here is the route:

Route::post('/search', 'Mobile\Estabelecimento\Estabelecimento@index');

Controller:

class Estabelecimento extends Controller {

public function index(Request $request) {
    $searchFor = $request->where;
    $result = DB::select('SELECT `f_search_estabelecimentos`(
        :onde) as Result', 
        [
            'onde' => $searchFor
        ]
    );

    return response()->json([
        'Mensagem' => 'Result for search estabelecimento.',
        'Success' => $result[0]->Result
    ]);
}
}

And here goes the Android Class that make the request:

  private void searchFor(String url, String volleyReq, final String userData) {
    progressBar.setVisibility(View.VISIBLE);

    StringRequest searchE = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            Log.d("Search_For Response", response);
            progressBar.setVisibility(View.GONE);
            try {
                JSONObject dataResponse = new JSONObject(response);

                Success = dataResponse.getInt(ServerTaggs.SUCCESS);
                if (Success == 1) {
                    Intent goodSearch = new Intent(Search.this, Estabelecimentos.class);
                    goodSearch.putExtra(ServerTaggs.DATA, userData);
                    goodSearch.putExtra(ServerTaggs.USER_ID, userId);
                    ActivityOptionsCompat transition = ActivityOptionsCompat.makeSceneTransitionAnimation(
                            Search.this, null
                    );
                    ActivityCompat.startActivity(Search.this, goodSearch, transition.toBundle());
                } else {
                    Snackbar.make(CL, R.string.no_records_on_research, Snackbar.LENGTH_LONG).show();
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d("Search_For Error", error.toString());
            progressBar.setVisibility(View.GONE);
            Snackbar sB = Snackbar.make(CL, R.string.serverError, Snackbar.LENGTH_LONG);
            View view = sB.getView();
            TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
            tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
            tv.setTextColor(ContextCompat.getColor(Search.this, R.color.colorIcons));
            sB.show();
        }
    }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> values = new HashMap<>();
            values.put(ServerTaggs.WHERE, userData);
            return values;
        }
    };

    VolleyAPI.getmInstance().addToRequestQueue(searchE, volleyReq);
}

But when I run the mysql 'SELECT f_search_estabelecimentos(:where)', this return True if in the database is the value 'where' or FALSE if isn't; But when the app run, always return FALSE even if the value exists on the database.

HELP GUYS. Thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire