Mobile app version of vmapp.org
Login or Join
Nimeshi995

: How to retrieve an image from MySQL database and display the image as background on body? How do I retrieve an image from MySQL database (I know how to display image by retrieving from database

@Nimeshi995

Posted in: #Css #Html #Images #Mysql #Php

How do I retrieve an image from MySQL database (I know how to display image by retrieving from database but here i want to display differently) i.e. display the image as background on body and image should repeat as if css repeat statement is used - the very same as on twitter.com.

I want to display an image on background (by using CSS repeat thing) the same way as on twitter but the problem is that I am retrieving it from a MySQL database and CSS cannot handle src tag on background.

I am very new to this and have been trying to solve this problem for 6 hrs but still it is not sorted out so please help. My code is PHP and MySQL (please tell me how to get URL for this image from the database and if I have to use CSS repeat)?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Nimeshi995

1 Comments

Sorted by latest first Latest Oldest Best

 

@Shakeerah822

body
{
background-image:url('http://www.example.com/background/get.php');
}


Edit:

To create a page that returns the image properly, you would do something like this (in PHP):

You stated you can already retrieve the image from the database, so assuming you have the appropriate SQL in $sql, that the image data is stored in a field named 'image', and you can connect to the database and everything:

$result = mysql_query($sql);

if ($row = mysql_fetch_array($result)){
header('content-type: image/jpeg');
imagejpeg(imagecreatefromstring($row['image']));
exit();
}


That's assuming the image is a jpeg. If it's not, you'll need to change the header and call the appropriate image function (like imagegif, imagepng, etc).

Now, put that page somewhere, say www.example.com/background/get.php, and use that as the background-image url.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme