显示数据库中的图像并将其链接到另一个页面


Displaying an Image from a database and linking it to another page

>我正在尝试显示数据库中的图像,但我想要这些正在显示的图像链接到另一个页面,您可以在其中评论它们。虽然它们能够在没有的情况下显示a 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>";

是的,你用那条线走在正确的轨道上 - 你在打开标签结束时缺少一个>:

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 之前查看)。