将数据库中的图像设置为背景图像的样式


Style image from database as background image

我想使用我在数据库中创建的图像引用作为背景:url。我已经设计好了=>[IMG]http://i49.tinypic.com/30ihudz.png[/IMG]。在我当前的代码中,我使用div样式来检索图像,但不会显示任何图像。有人能指引我吗?提前谢谢。

public function displayProduct()
{
if($product = $this->db->query("SELECT id, title, description, price, filename FROM trips ORDER BY id"))
            {
                while ($row = $product->fetch_assoc())
                            {
                        $output .= '<div class="reisbox">';
                                $output .= '<div id="reis_insidebox1" style=" background: url("C:/xampp/htdocs/webshop/public/img/content/"'.$row['filename'].' ") width="1000" height="500">';
                                $output .= '<div class="reis_textbox">';
                                $output .= '<h2>'.ucfirst($row['title']).'</h2>';
                                    $output .= '<article>';
                                    $output .=  ucfirst($row['description']);
                                    $output .= '</article>';
                                    $output .= '</div>';
                                $output .= '<div class="rightboxx">';
                                $output .= '<div class="reis_price_box">';
                                $output .= '<div class="reis_price_box_text">';
                                $output .= '&euro;'.$row['price'];
                                $output .= '</div>';
                                $output .= '<div class="more_box">';
                                $output .= '<a href="index.php?page=reis.php&pid='.$row['id'].'"><p>Lees meer..</p></a>';
                                $output .= '</div>';
                                $output .= '</div>';
                                $output .= '</div>';
                                $output .='<br />';
                                $output .= '<div id="add">';
                                $output .='<a href="index.php?page=cart.php&action=add&id='.$row['id'].'"><p>Add to cart</p></a>';
                                $output .= '</div>';
                        $output .= '</div>';
                                $output .= '</div>';
                    }
                    return $output;
                }
        }

如果你真的想从"C:''examplep/…/"中获取文件,你应该在前面添加一个文件:///infront,但我想你只是想使用一个相对路径,比如"img/content/and thefilenamefromdatabase.png">

为了继续,您实际上是在CSS背景中用"关闭style标记,您可能想在那里使用',或者简单地完全跳过字符串文字

考虑到这一切,它可能看起来是这样的:

$output .= '<div id="reis_insidebox1" style="background: url(''img/content/'.$row['filename'].''')" width="1000" height="500">';

请注意,我在这里使用反斜杠转义CSS中的'