It's close but not quite. Check the examples at
http://php.net/manual/en/mysqli.query.php and
http://php.net/manual/en/mysqli-result.fetch-assoc.php and
http://php.net/manual/en/mysqli-result.fetch-all.php
Edits below.
I would also consider looking up Binding variables instead of injecting session variables into a query. A malicious user could potentially set your $user_year variable and edit the query. More here: http://php.net/manual/en/mysqli-stmt.bind-param.php
<?php
session_start();
$user_year = $_SESSION['year'];
$floor = $_SESSION['year_floor'];
include "config.php"; //I assume you create a $mysqli object here
$query = "select * from timetable where year = '$user_year'";
$results_array = array(); // I try to avoid using variable types as names so have renamed to results_array
$result = $mysqli->query($query); // mysqli runs the query (see man above)
//The result runs the fetch_assoc (see man above)
while($row = $result->fetch_assoc()){
$result_array[] = $row;
}
// If you know you have a small result set you could replace the while() loop above with $result_array = $result->fetch_all()
// echo '<script>console.log(\"$array\")</script>'; (this wont work because the client side javascript can't understand the php variable. But you could place this line inside the loop above.)
// debug:
print_r($result_array); // show all array data
echo $result_array[0]['username']; // print the first rows username
$mysqli->close(); // you don't need to do this unless saving memory mid script, but it's good practice so I left it in
?>