This question already has an answer here:
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.
<?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->fetch_assoc()){
$array[] = $row;
}
echo '<script>console.log(\"$array\")</script>';
/* close connection */
// debug:
print_r($array); // show all array data
echo $array[0]['username']; // print the first rows username
$mysqli->close();
?>
This is what I have pieced together so far, is this close? Any pointers in the right direction would be great thanks.
</div>