2013-10-12 34 views
0

我試圖從數據庫中顯示圖像,但我希望這些正在顯示的圖像 能夠鏈接到您可以對其進行評論的另一個頁面。雖然他們能夠在沒有 的情況下顯示href,第二個我放入,圖像不再顯示,並且它們沒有錯誤指示原因。從數據庫顯示圖像並將其鏈接到另一個頁面

這裏是PHP

require("config.php"); 

$dbc = mysqli_connect ($db_host, $db_user, $db_password, $db_name) OR die ('Could not connect to MySQL: '. mysqli_connect_error()); 

$sql = "SELECT * from image" ; 
$result = mysqli_query($dbc, $sql) or die ("Could not access DB: " . mysqli_error()); 

// Insert a back to browse button here? 

while ($row = mysqli_fetch_assoc($result)) 
{ 
    echo "<div class=\"picture\">"; 
    echo "<p>"; 
    echo "<a href=\"comments.php?image={$row['image_id']}\"<img src=\"upload/" . $row['filename'] . "\" alt=\"\" /></a>"; 
    echo $row['title'] . "<br />"; 
    echo "</div>"; 
} 

    ?> 

我假設有一些在這裏語法錯誤,我沒有意識到。

echo "<a href=\"comments.php?image={$row['image_id']}\"<img src=\"upload/" . $row['filename'] . "\" alt=\"\" /></a>"; 

回答

0

是的,你是與該行的正確軌道 - 你缺少一個>在你打開一個標籤的末尾:

echo "<a href=\"comments.php?image={$row['image_id']}\"<img src=\"upload/" . $row['filename'] . "\" alt=\"\" /></a>"; 

應該是:

echo "<a href=\"comments.php?image={$row['image_id']}\"><img src=\"upload/" . $row['filename'] . "\" alt=\"\" /></a>"; 

(如果看不到有什麼變化,請在img之前查看)。

+0

Omg有史以來最好的人,謝謝!我知道這是小事! – smilefreak24

+0

太棒了!沒問題;祝你網站好運:) –

相關問題