Hello There Fellow Devs! I’m trying to retrieve an image from my database to include it with this table I created. All the Examples I looked up on Google are for retrieving images from 1 table alone that contains only images, but in this case I can’t get it working.
<?php
$Con = mysql_connect('localhost','root','');
if($Con === false)
{
echo "Not Connected";
}
else
{
$select = mysql_select_db("symfony");
$TableName = "main";
$SQLstring = "SELECT * FROM $TableName ";
$QueryResult = mysql_query($SQLstring);
$Row = mysql_fetch_row($QueryResult);
do {
echo "<div class='art-content-layout'>";
echo "<div class='art-content-layout-row'>";
echo "<div class='art-layout-cell' style='width: 33%'>";
echo" <p><img width='259' height='194' class='art-lightbox' name='image' src='../images/3.jpg'><br></p>";
echo "</div>";
echo "<div class='art-layout-cell' style='width: 67%'>";
echo "<p></p>";
echo "<table border>";
echo "<tbody>";
echo "<tr>";
echo "<tr>";
echo "<th colspan='3' align='left'><b> Owner : $Row[0]</b></th>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='3'><b>$Row[1]:</b>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>Price:$Row[9] US Dollar </b></td>";
echo "</tr>";
echo "<tr>";
echo "<td><b> City: $Row[4] </br> Hood: $Row[4] </br> Qdr: $Row[5] </br> Street:$Row[6] </br> Property Number :$Row[7] </br> Room Number : $Row[8] </b></td>";
echo" <td><b>Description : $Row[10] </b></td>";
echo "</tr>";
echo"<tr>";
echo" <td><b>Type : $Row[12] </b></td>";
echo "<td><b>Contact : $Row[1] </b></td>";
echo "</tr>";
echo "</tr>";
echo "</tbody>";
echo "</table> <br><p></p>";
echo "</div>";
echo "</div>";
echo "</div>";
$Row = mysql_fetch_row($QueryResult);
} while ($Row);
}
?>
I tried to do this, it still didn’t work :
$img = $Row[15];
//column 15 is the Blob the image
$img = mysql_fetch_array($QueryResult);
$content = $img['15'];
//header('Content-type: image/jpg');
You can’t do what you are trying to do. You need to separate your logic into two scripts. There really isn’t a way to get the image data in the same pass as your other data because the IMG tag is fed a SRC that is not raw data, but instead asks the server to serve the image.
In your current script where you generate the HTML you just need to have your IMG tag reference the SRC as a new script that does the work of retrieving your image data. Something like:
I’m assuming there that $Row[0] holds the unique key for the current record. Then you write another script, display_image.php that fetches just the image data and uses the proper headers to display it: