2013-02-24 64 views
0

我想使用我在數據庫中做的圖像引用作爲背景: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; 

       } 
     } 
+0

您正在使用來自Windows硬盤的圖像的路徑; '「C:/ XAMPP/htdocs中/網店/公共/ IMG /內容/"'.$行[ '文件名']「。 「'這是打算的嗎?我想你應該使用一個相對於網站目錄樹的路徑,也許就像''/img/content/"'.$row['filename']'。' 「' – 2013-02-24 15:01:21

回答

0

如果你真的想從文件中取出「C:/ XAMPP /.../」你應該添加一個文件:///盈,但我猜你只是想使用相對路徑,例如作爲「IMG /內容/ andthefilenamefromdatabase.png」

,繼續,你實際上是關閉您的style - 標籤在你的CSS背景",你可能需要使用'存在或者乾脆跳過字符串字面完全

所有這一切都是介意,它可能看起來像這樣:

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

請注意,我在這裏使用反斜槓在CSS中跳過'

+0

它表示無效的屬性值,元素樣式爲n chrome,不顯示圖片 – HansWorst 2013-02-24 16:32:36

+0

生成的html如何顯示?該div具體嗎?我只是注意到我錯過了一個關閉樣式的''',我現在更新了它。 – hank 2013-02-24 16:37:17

+0

它現在看起來幾乎像現在的樣子,非常感謝 – HansWorst 2013-02-24 17:13:00