I have the below code to display content from a database. The while loop is supposed to display data in a table row. The output is different: the data from the database are displayed before the table. The while seems to run and ignore the html tags, and then run again and ignore the variables.

PHP Code:

```
// Instantiate database
$database = new Database();
$db = $database->getConnection();

// List transactions without bundles
$query = "SELECT * FROM stock_trx WHERE bundleId IS NULL";
$statement =  $db->prepare($query);
$statement->execute();
$n = $statement->rowCount();

if($n > 0){

    echo "<table>
        <thead>
            <tr>
                <th>Select</th>
                <th>Date</th>
                <th>Type</th>
                <th>Quantity</th>
                <th>Ticker</th>
                <th>Amount</th>
                <th>Currency</th>
            </tr>    
        </thead>
        <tbody>";

    // Retrieve table content
    while($row = $statement->fetch(PDO::FETCH_ASSOC)){
        // Extract row
        extract($row);

        echo "<tr>".$id."</tr>";
        echo "<tr>".$date."</tr>";
        echo "<tr>".$type."</tr>";
        echo "<tr>".$qty."</tr>";
        echo "<tr>".$ticker."</tr>";
        echo "<tr>".$amount."</tr>";
        echo "<tr>".$currency."</tr>";

    }

    echo "</tbody></table>";
} else {
    echo "No transaction";
}

```

HTML output:

```
<html>
<body>

12020-05-13 00:00:00BUYTEST1000022020-05-19 00:00:00SELTEST1200032020-05-24 00:00:00DIVTEST250<table>
        <thead>
            <tr>
                <th>Select</th>
                <th>Date</th>
                <th>Type</th>
                <th>Quantity</th>
                <th>Ticker</th>
                <th>Amount</th>
                <th>Currency</th>
            </tr>    
        </thead>
        <tbody><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr>
        </tbody>
    </table>

</body></html>

```

Thank you