title: How to convert Mysqli results into an array in OO Php
body: <p>I want to retrieve data from a table in database and display the result in an array in the form below.</p>
  
  <p>array("1"=>"Value 1", "2"=>"value2")
  Here is the function I tried using but I get error when I try to display the array. Please I need help on this. I'm new to OO Php.</p>
  
  <pre><code>&lt;?php
  class query {
  
  public function listfields (){
      $result = $this-&gt;mysqli-&gt;query("SELECT id, name FROM fields", MYSQLI_USE_RESULT);
      while($row=$result-&gt;fetch_assoc()){
      $this-&gt;fields[$row["id"]] = $row["name"];
      }
      $result-&gt;free();
  
  }
  
  public function fields(){
  return $this-&gt;fields;   
  }
          }
  
  
  $list = new query;
  $list-&gt;listfields();
  $field1 = $list-&gt;fields();
  
  echo $field1;
  ?&gt;
  </code></pre>