Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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)?

share|improve this question

closed as off topic by John Conde Jan 1 '13 at 20:50

Questions on Webmasters Stack Exchange are expected to relate to webmastering within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

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 http://www.example.com/background/get.php, and use that as the background-image url.

share|improve this answer
    
no sir thats the problem can u help me to figgure this out please @Eric Brandel –  user1938039 Jan 1 '13 at 18:43
    
see my updated answer –  Eric Brandel Jan 1 '13 at 19:11
    
which page sir? –  user1938039 Jan 1 '13 at 19:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.