title: Retrieving rows from database and storing to session arrays
body: <p>I am trying to retrieve rows from a database and store them to an array/ session array (I am a bit lost). The database I am currently retrieving from has 3 rows.</p>
  
  <pre><code>&lt;?php
  session_start();
  $user_year = $_SESSION['year'];
  $floor = $_SESSION['year_floor'];
  
  include "config.php";
  $query = "select * from timetable where '$user_year' = year;
  $array = array();
  
  while($row = $query-&gt;fetch_assoc()){
    $array[] = $row;
  
  }
  
    echo '&lt;script&gt;console.log(\"$array\")&lt;/script&gt;';
    /* close connection */
    // debug:
    print_r($array); // show all array data
    echo $array[0]['username']; // print the first rows username
    $mysqli-&gt;close();
  ?&gt;
  </code></pre>
  
  <p>This is what I have pieced together so far, is this close?
  Any pointers in the right direction would be great thanks.</p>