Getting correct run order in a while($x = $y->fetch_assoc()){} loop

Just started playing around with php and mysql, loading small images from a database and stumbled across this little problem. Can anyone help me get the right display order and explain why what I’m doing doesnt work? What I want is this:

Database contains x items.
<img 1>
Text under image.
<img 2>
Text under image.

But with this code:

if ($result->num_rows > 0) {
echo "Database contains ".$result->num_rows." items.";
// output data of each row
while($row = $result->fetch_assoc()) {

  $src = "data: ".$row['jpgornot'].";base64,".$row['pic'];

  echo "<img src = '" . $src . "'><br><br>";
  echo "Text under image.";
}

}

I get:

<img 1>
Database contains x items.
<img 2>
Text under image.
Text under image.