The problem you have is not headers or mime-types, it's the fact that to display the image, the binary output needs to be in it's own file. When you try to tell the page to be a binary image but throw in some HTML output along with it, you currupt the binary file image header.
To keep the database activity down and avoid a second query, what I would do is actually create the image as a file on the server by writing it out from the DB result and then having the <img> tag reference that file. You could also get tricky with it by writing out a PHP file that echos the binary data after sending out the appropriate header (img/jpeg etc) and then unlink() itself for automatic garbage disposal.
But anyway you do it, you'll need to have a second file to act as the actual image.
So sayeth the sheppard, so sayeth the flock!