Displaying Image From MySQL
I have images stored in a field called 'Photo' in a MySql table called 'Authors', and I am trying to figure out a way to display these images from the table. The code I have is:
Code:
// Define the query.
$query = 'SELECT * FROM Authors';
if ($r = mysql_query ($query)) { // Run the query.
// Retrieve and print every record.
while ($row = mysql_fetch_array ($r)) {
print "<p><h3>{$row['First_Name']} {$row['Last_Name']}</h3>
<p>{$row['Biography']}<p/>
<img src=\"{$row['Photo']}\">
<a href=\"edit_entry.php?id={$row['blog_id']}\">Edit</a>
<a href=\"delete_entry.php?id={$row['blog_id']}\">Delete</a>
</p><hr />\n";
}
} else { // Query didn't run.
die ('<p>Could not retrieve the data because: <b>' . mysql_error() . "</b>. The query was $query.</p>");
} // End of query IF.
mysql_close(); // Close the database connection.
Everything works okay, except I get the usual white box with the red x in it because the image will not display.
The 'Photo' field is a LONGBLOB field. Where did I go wrong?
Displaying Image From MySQL - Resolved
The mind can only take so much and, in the time that I have left to live, life is too short. Whereas this is not as simple as it should be, I've decided to go along with simply storing a reference to the actual image file. This seems to me the preferred method, and it works for me. ;)