2013-11-26 65 views
0

我试图通过从数据库和内嵌样式得到一个目录目录错误

<div class="query"> 
    <?php 
    if ($type == "category") { 
    $query = "SELECT * FROM shopItems WHERE category = '" . $_GET['query'] ."'"; 
    $result = mysqli_query($con, $query); 
    $i = 0; 
    while ($row = mysqli_fetch_array($result)) { 
     $i = $i + 1; 
     $url = '../img/'.$row['imgSRC']; 
     if ($i % 2 != 0) { 
      if ($i != 1) { 
       echo '</div>'; 
      } 
      echo '<div class="queryRow"><div class="item" style"background:url(' . $url . ') no-repeat; background-size:contain;">' . $row['productName'] . '</div>'; 
     } else { 
      echo '<div class="item" style"background:url(' . $url . ') no-repeat; background-size:contain;">' . $row['productName'] . '</div>'; 
     } 
    } 
    echo "</div>"; 
    ?> 
</div> 

我的问题来加载每个DIV一个单独的图像,当曾经在页面加载斜线( “/”)在$ url变量被替换为空格,所以浏览器认为一个无效的URL已经给了,我该如何解决这个问题?

+0

这可能是不可能的。我认为网址已经存储了空格的斜杠 –

+0

请显示$ url var的值和div中的最终输出。 – 2013-11-26 16:39:40

回答

0

尝试

style = "background:url(' . $url . ') no-repeat; background-size:contain;"

,而不是

style"background:url(' . $url . ') no-repeat; background-size:contain;"

echo '<div class="item" style = "background:url(' . $url . ') no-repeat; background-size:contain;">' . $row['productName'] . '</div>'; 
+0

谢谢,我没有注意到,出于某种原因编辑$ url字符串 – tht13