E
E
Egor Vinogradov2021-11-21 14:14:56
PHP
Egor Vinogradov, 2021-11-21 14:14:56

How to insert a link to a photo taken from sql into the style attribute with the background property?

In short, the inhabitants of habr, the problem is again, here is the code:

<?php while ($article = mysqli_fetch_assoc($articles))
                 {
                 ?>
                          <div class="newsblock" style="background:url(https://ссылка.jpeg) 0 0 / auto 100% no-repeat;
">
<div class="base">
<a class="white_font_big" href="#"><?php echo $article['main'];?></a>
<a href="#" class ="white_font_small"><?php echo $article['article_txt'];?></a>
</div>
</div>
                        
<?php } ?>

In short, the bottom line is that I take values ​​from the database and substitute them in the necessary tags, as a result, everything is displayed as a square block with news, and the problem is that each such block should have its own background, a link to which is specified in the database, I decided to use style ="background: url ();" since this is the very first thing that came to mind, it is possible to get a link to the photo, but I don’t know how to put it in the url value, does anyone have any thoughts?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan K, 2021-11-21
@Silwa

Get the link to the photo in a variable, for example $img
Next

<div class="newsblock" style="background:url(<?php echo $img; ?>) 0 0 / auto 100% no-repeat;">

Or right away
<div class="newsblock" style="background:url(<?php echo $article['как у тебя называется фон'];?>) 0 0 / auto 100% no-repeat;">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question