|
-
Aug 26th, 2012, 08:46 PM
#1
Thread Starter
Fanatic Member
[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.
Manny Pacquiao once posted in his twitter:
It doesn't matter if the grammar is wrong, what matter is that you get the message
-
Aug 26th, 2012, 11:32 PM
#2
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.
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Aug 27th, 2012, 05:52 AM
#3
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 )
-
Aug 28th, 2012, 06:15 PM
#4
Thread Starter
Fanatic Member
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.
Manny Pacquiao once posted in his twitter:
It doesn't matter if the grammar is wrong, what matter is that you get the message
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|