Skip to content
Advertisement

Adding PHP to background-image url

This is what I have so far but it’s not working. This is my css:

background-image: url("upload/blog/'.$row["urlImg"].'");

Here is the full code:

<?php 
  $stmt = $db->query
  ( 'SELECT blog.postID, blog.postTitle, blog.postSlug, blog.postDesc, blog.urlImg, blog.postTags, blog.postDate
     FROM blog, blog_post_cats
     WHERE blog.postID = blog_post_cats.postID AND blog_post_cats.catID = 4 ORDER BY postID DESC LIMIT 1'
  ); 
  while($row = $stmt->fetch())
  {
    echo '<article style="background-image: url(upload/blog/'.$row['urlImg'].'" );"> '; 
  }
?>

This PHP echo does not work.

clicke to view output screenshot ,the blank space is the error ,others are url images

Advertisement

Answer

thank y’all for your contributions

i got this myself

i just added my website address to it @https://mywebsite.com/upload/blog/...

 echo '<article style="background-image: url(https://mywebsite.com/upload/blog/'.$row["urlImg"].'");"> ';
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement