title: Display all images stored as BLOB data from MySQL database
body: <p>I have uploaded some images to MySQL using PHP. I can also display 1 image everytime i modify the id in the HTML img tag. 
  But now I'm trying to display all images stored in MySql database and the problem is when i use a 'While Loop' it only shows the text columns and not the images stored as BLOB data in MySQL...</p>
  
  <p>I have a database called: <em>my_db</em>
  I have a table called: <em>blob</em>
  And i have 3 columns in my table: <em>id</em>, <em>name</em> &amp; <em>image</em></p>
  
  <p><strong>here is the code for the index.php:</strong></p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;form action="index.php" method="POST" enctype="multipart/form-data"&gt;
      &lt;input type="file" name="image"&gt;&lt;input type="submit" name="submit" value="Upload"&gt;
  &lt;/form&gt;
  &lt;?php
  
  if(isset($_POST['submit']))
  {
      mysql_connect("127.0.0.1","root","");
      mysql_select_db("my_db");
  
      $imageName = mysql_real_escape_string($_FILES["image"]["name"]);
      $imageData = mysql_real_escape_string(file_get_contents($_FILES["image"]["tmp_name"]));
      $imageType = mysql_real_escape_string($_FILES["image"]["type"]);
  
      if(substr($imageType,0,5) == "image")
      {
          mysql_query("INSERT INTO `blob` VALUES('','$imageName','$imageData')");
          echo "Image Uploaded!";
      }
      else
      {
          echo "Only images are allowed!";
      }
  
  }
  
  ?&gt;
  
  &lt;img src="showimage.php?id=11"&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>And here is the code for showimage.php:</strong></p>
  
  <pre><code>&lt;?php
  
  mysql_connect("127.0.0.1","root","");
  mysql_select_db("my_db");
  
  if(isset($_GET['id']))
  {
      $id = mysql_real_escape_string($_GET['id']);
      $query = mysql_query("SELECT * FROM `blob` WHERE `id`='$id'");
      while($row = mysql_fetch_assoc($query))
      {
          $imageData = $row["image"];
      }
      header("content-type: image/jpeg");
      echo $imageData;
  }
  else
  {
      echo "Error!";
  }
  
  ?&gt;
  </code></pre>
  
  <p>Thanks in advance :-)</p>