[RESOLVED] PHP Displaying images that are stored in a blob field
This is my code and somehow it works.
Code:
<table border="1">
<?php
mysql_connect("localhost", "root") or die("Cannot connect to database: ".mysql_error());
mysql_select_db("db_pcaccess") or die("Cannot connect to database: ".mysql_error());
$category = "Monitor";
$query = mysql_query("SELECT * FROM tbl_products WHERE pcategory='".$category."'");
$a = 1;
while ($row = mysql_fetch_array($query))
{
if($a <= 3){ //number of cells in a row
echo '<td>'.$row['pimage'].'</td>';
$a++;
}
else{
echo '</tr>\n<td>'.'<td>'.$row['pimage'].'</td>';
$a = 1;
}
}
echo '</tr>';
?>
</table>
The problem is i don't know where to put this code so that it tells the browser that the file would be a jpg file.
Code:
header('Content-type: image/jpg');
I tried displaying a single image without the table and it works. But when I add the table code and the loop, it doesn't display the images that I've put in the database. Please help. I'm only a beginner in PHP.
Re: PHP Displaying images that are stored in a blob field
Check this: http://stackoverflow.com/questions/5...n-a-mysql-blob
One more thing, avoid using mysql_* functions for db interaction. Instead use, mysqli or PDO.
:wave:
Re: PHP Displaying images that are stored in a blob field
Thread moved from the 'XML, HTML, Javascript, Web and CSS' forum to the 'PHP' forum
(thanks as always for letting us know akhileshbc :thumb: )
Re: PHP Displaying images that are stored in a blob field
Thanks for the reply akhileshbc.
I'll check the link that you gave me.
Sorry for posting in the wrong section.