How to select multiple records from SQL and insert into a Session
<p>I am looking for how to insert multiple records from a SQL table into a session variable, or into multiple unique session variables.</p>

<pre><code>$userID = $_SESSION['user']['id']; 

$coursequery = " 
            SELECT
                coursename,
                location,
                description 
            FROM courses 
            WHERE 
                teacherID = '$userID' 
        "; 

        try 
        { 
            $stmt = $db-&gt;prepare($coursequery); 
            $result = $stmt-&gt;execute(); 
        } 
        catch(PDOException $ex) 
        {  
            die("Failed to run query: " . $ex-&gt;getMessage()); 
        } 

        $row = $stmt-&gt;fetch(); 

            $_SESSION['courseinfo'] = $row;   
</code></pre>

<p>The table "courses" has a few records inside, all with the teacherID being that of the current userID, defined at the start. When I print_r($_SESSION['courseinfo']); it only displays one of the records in the table.</p>

<p>I'm trying to create a loop that displays all the information grabbed, for each record, since you won't know for sure how many records you'll grab at any given time. Any answers are greatly appreciated!</p>