2012-09-14 26 views
1

我無法正確顯示存儲在我的數據庫中的URL。這是我的代碼:mySQL數據庫和PHP中的URL字符串

$sqlCommand = 
     "SELECT rotator.title, rotator.imageURL, rotator.targetURL, rotator.caption FROM rotator 
     WHERE ((rotator.visible = '1') 
     OR (rotator.visible = '2' AND (NOW() BETWEEN rotator.schedstart AND rotator.schedstop))) 
     ORDER BY rotator.displayorder ASC"; 
    $query = mysqli_query($myConnection,$sqlCommand) or die (mysqli_error($myConnection)); 

    $rotatorsDisplay = ''; 
    while ($row = mysqli_fetch_array($query)){ 
     $rotatorstitle = $row["title"]; 
     $rotatorsimg = $row["imgURL"]; 
     $rotatorsURL = $row["targetURL"]; 
     $rotatorscaption = $row["caption"]; 

     $rotatorsDisplay .= '<li> 
       <a href="'. $rotatorsURL .'"><img src="'. $rotatorsimg .'"></a> 
       <div id="title">'. $rotatorstitle .'</div> 
       <div class="caption">'. $rotatorscaption .'</div> 
      </li>'; 
    } 
    mysqli_free_result($query); 

引起我麻煩的是$ rotatorsimg變量。在數據庫中,我手動輸入了rotator.imageURL的值,如下所示:'images/rotator/name.jpg',但是當我從數據庫中查詢它們時,將它們添加到$ rotatorsDisplay變量中,然後使用此代碼輸出它們:

<?php echo $rotatorsDisplay; ?> 

所有我在結果頁面得到的是:

<a href="doctor.php"><img src=""></a> 

我敢肯定,這是不工作的原因是在URL中的斜槓。我也很確定我需要以某種方式編碼/轉換HTML以從我輸入到我的數據庫的代碼中去掉特殊字符,然後在輸出時將其解碼/轉換回HTML,但是由於我手動輸入了這個信息到數據庫中phpMyAdmin,我還沒有制定出如何做到這一點。

任何幫助表示讚賞!

回答

3

它看起來像你使用錯誤的索引鍵。

$rotatorsimg = $row["imgURL"]; 

大概應該是

$rotatorsimg = $row["imageURL"]; 

,因爲這是你從數據庫中查詢什麼。

+0

非常感謝。我知道它必須是非常明顯的東西。 – Michelle

相關問題