-3

I have this database table:

ID Nome Country Imagem
1  John USA     images/######.jpg
2  Ana  USA     images/######.jpg
3  ##   ##      images/######.jp

How can I start my code? I Want to get the image through the ID and put it in the background.

.background {
   backgound-image: url(...);
}

Is This Possible?

chris85
  • 23,846
  • 7
  • 34
  • 51

3 Answers3

0

I think it's possible when you link php file as css.

And return appropriate header

Like here: https://stackoverflow.com/a/2906870/1011278

2) Second variant is to do something like this:

.background {
   backgound-image: url(/user-image.php?id=1);
}

If i got right.

Community
  • 1
  • 1
murrometz
  • 904
  • 1
  • 8
  • 12
0

You can write your css code in your header.php or footer.php like,

<?php
$imgUrl = 'images/######.jpg';  //get corresponding filename and path from db
?>
<style>
.background {
   backgound-image: url(<?php echo $imgUrl ?>);
}
</style>
<?php
?>
Jobz
  • 424
  • 1
  • 4
  • 13
-1

Do you know MySQL?

Anyway, after the connection to the DB, do this:

$bg = $mysqli->query("SELECT Imagem FROM YOURTABLE WHERE ID=2")->fetch_object()->Imagem;
Theraloss
  • 700
  • 2
  • 7
  • 30
  • You shouldn't recommend the usage of `mysql_` functions. Also seems to broad to be answered at this time. HTML and CSS will be needed.. – chris85 Sep 09 '15 at 15:52
  • You canno't directly connect CSS to PHP, so you need to put the css code in your HTML page and in "background: url()", put `` – Theraloss Sep 09 '15 at 15:56