如何在新窗口中打开数据库中显示的图片

How to open a pictute displayed from the DB in a new window?

本文关键字:显示 在新窗口中打开 数据库      更新时间:2023-09-26

我有一个页面显示了几张图片。每个图像路径都存储在数据库中,这就是我使用php显示它们(从它们的路径)的方式。

我如何才能让用户点击图片时,它会在新窗口或弹出窗口中打开?我看了很多东西,但没有显示如何对数据库中的输出进行处理。这是我的代码:

<!DOCTYPE HTML>
<html>
<body>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="jquery.imagemapster.js"></script>
<link rel="stylesheet" type="text/css" href="css.css" />

<title>VisitBulgaria</title>
</head>

<div class="banner">


<a href="home.html">
<img src="images/banner.png"   alt="home" border="0" height="150" width="500" /></a>
<div class="namelog">

<?php 
if (isset($_SESSION['ID'])){

 echo $Forename." ".$LastName; 
 echo '<a href="logout.php">Logout</a> &sol; '; 
 echo '<a href="userpage.html">Account</a>'; 
}
 else {
 if (!isset($_SESSION['ID'])){

 echo '<a href="login.php">Log In</a> &sol; ';
 echo '<a href="register.php">Register</a>';
 }
}
?>
</div>

<div class="center11">

<div class="attractions2">

<?php 

if (!$link = mysql_connect()) {
    echo 'Could not connect to mysql';
    exit;
}
if (!mysql_select_db('visitbulgaria', $link)) {
    echo 'Could not select database';
    exit;
}

$villageId = $_GET['village']; 
$sql    = "SELECT `AttractionID`, `Name`, `Location`, `Description`, `Airport`, `imglink`,`imglink2`,`imglink3`,`imglink4`,`imglink5`  FROM `attractions` WHERE `AttractionID`='$villageId'";
$result = mysql_query($sql, $link);
if (!$result) {
    echo "DB Error, could not query the database'n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}

while ($row = mysql_fetch_assoc($result)) {
    echo $row['Name']; 
    echo "<br />" ;
    echo " Location: ".$row['Location'] ." ";
    echo "<br />" ;
    echo $row['Description'];
    echo "<br />" ;
    echo " Nearest Airport: ".$row['Airport'] ." ";
    echo "<br />" ;
    echo "<br />";
    echo '<img src="'.$row['imglink'].' " height="200" width="500">';
    echo "<br />";
    echo '<img src="'.$row['imglink2'].' " height="250" width="250">';
    echo "&nbsp";
    echo '<img src="'.$row['imglink3'].' " height="250" width="250">';
    echo "<br />";
    echo '<img src="'.$row['imglink4'].' " height="250" width="250">';
    echo "&nbsp";
    echo '<img src="'.$row['imglink5'].' " height="250" width="250">';


echo "<a href='favourite.php?village=" . $row['AttractionID'] . "  '>" . 
 "<img src='img/fav.png'  > 

       </a>";

}


mysql_free_result($result);

 ?>

 </body>
</html>

将target="_blank"添加到每个img href,例如

 echo '<a href="'.$row['imglink'].'" target="_blank"><img src="'.$row['imglink'].' " height="200" width="500"></a>';