title: How to select all records from SQL database and put it in Listview Android
body: <p>Im trying to learn how to store and get record from a database for android application, i can do update, insert, delete etc. but i have problem in getting more than one record, I want to ask how to get all records from a table in localhost phpmyadmin and export the result into the listview in android application using shared preferences, here is my php function code: </p>
  
  <pre><code> public function getLessons($teacher) {
  
  $sql = 'SELECT * FROM lessons WHERE teacher = :teacher';
  $query = $this -&gt; conn -&gt; prepare($sql);
  $query -&gt; execute(array(':teacher' =&gt; $teacher));
  $data = $query -&gt; fetchObject();
  
  $lesson["title"] = $data -&gt; title; // im not sure if this is true
  $lesson["maxstudent"] = $data -&gt; maxstudent; // im not sure if this is true       
  $lesson["about"] = $data -&gt; about; // im not sure if this is true
  return $lesson;// the result of sql query will be more than one record 
  }
  </code></pre>
  
  <p>the code above will retrieve the result of query, but im not sure about the code, what is the result of lesson if the result is more than one record? is that an array of string?and here is my java method to get all lesson in the database code:</p>
  
  <pre><code>        private void getLessonProcess(String teacher){
  
          Retrofit retrofit = new Retrofit.Builder()
                  .baseUrl(Constants.BASE_URL)
                  .addConverterFactory(GsonConverterFactory.create())
                  .build();
  
          RequestInterface requestInterface = retrofit.create(RequestInterface.class);
  
          Lesson lesson = new Lesson();// its Java Class containing title,maxstudent and about
          lesson.setTeacher(teacher);// we set the teacher, so only specific teacher's lesson will be given as a result
          ServerRequest request = new ServerRequest();// server request is a class to connect to localhost
          request.setOperation(Constants.LESSONS);// constants.LESSONS is 'getlessons' the key that i use to trigger the SQL Query above
          request.setLesson(lesson);
          Call&lt;ServerResponse&gt; response = requestInterface.operation(request);
  
          response.enqueue(new Callback&lt;ServerResponse&gt;() {
              @Override
              public void onResponse(Call&lt;ServerResponse&gt; call, retrofit2.Response&lt;ServerResponse&gt; response) {
  
                  ServerResponse resp = response.body();
                  Snackbar.make(getView(), resp.getMessage(), Snackbar.LENGTH_LONG).show();
  
  
                    if(resp.getResult().equals(Constants.SUCCESS)){
                          SharedPreferences.Editor editor = pref.edit();
                          editor.putString(Constants.LESSONS,resp.getLesson().getLessontitle());
                          editor.putString(???,resp.getLesson().getMaxstudent());
                          editor.putString(???,resp.getLesson().getAbout());
                          ?????????? // What should i write here?
                          //in code above it will only put one record of the database and put it in shared preference 
                          editor.apply();
                      }
                  }
  
                  @Override
                  public void onFailure(Call&lt;ServerResponse&gt; call, Throwable t) {
  
                      Log.d(Constants.TAG,"failed");
                      Snackbar.make(getView(), t.getLocalizedMessage(), Snackbar.LENGTH_LONG).show();                 
  
              }
          });
      }       
  </code></pre>
  
  <p>is that possible to iterate through all the data and put it in an arraylist so that i can use adapter to show the result in ListView? Thank You</p>