Jump to content

calling images from a database??


nicolem798

Recommended Posts

MM I obviously have no idea about this any pointers please.

 

I have just resized and added a thumbnail to my database and now i am tring to call it from the database on a page to be read and it is just displaying aload of nonsense data??

Code:

 

ÔuK‰ ½¼Žõ*HÂ{tà`àg'$pLúgÂ?µ1—VF!p|¢0@ žƒŒôã=8ÁäŸ7†2Ê8iÔÅâ§í9ɹ&ÚkšêMZÎV÷ŸÆÓÑ·m~j5ò\¦U18¼\'^1n(ûõ[j.ÑI¶µm>k;nôÓâ°Þ'ñÇÙ-¡™·2 v:üăî€Î:“ÛŸ`ð—ìÿ©ê —‚´Jçsd

 

the page is full of it like above??

 

 

This is what I am using to call it.

 

<td>
<?
$query = "SELECT thumbnail FROM uploads where intProductID=$adid";
$result = MYSQL_QUERY($query);
$data = MYSQL_RESULT($result,0,"thumbnail");

?>
<img src="<?=$data?>" />
</td>

Link to comment
https://forums.phpfreaks.com/topic/138468-calling-images-from-a-database/
Share on other sites

I wouldnt advise saving images to ur database. Upload the image you want to call into a folder on ur server, save the image name to your database and call it dynamically e.g

 

<Img src="images/<?php echo $img ?>" />

Where $img is a variable representing your image recordset.

I also won't save images in the database.

 

But remember the difference of an html-page and an image:

html is plain text, images is not plain text. So you can't just output the image-source into the html page.

 

Create a new file for the image and write the following:

<?php
//... here should be the connection for the database
$query = "SELECT thumbnail FROM uploads where intProductID=$adid";
$result = mysql_query($query); //PHP-Function are mostly written in lower-case!!!
$data = mysql_result($result,0,"thumbnail");

header('Content-type: image/png'); /* I don't know which type of image you are outputing
but you need to change the header */
echo $data;

?>[code]

And in you html-code (if the file is called image.php):
[code]<img src="image.php" />

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.