【发布时间】:2015-03-15 05:06:49
【问题描述】:
我正在尝试使用从数据库中检索到的缩略图。 PHP 工作正常并显示我的缩略图。我不知道如何将数据库中的 id 获取到 JavaScript 函数的 imageID 和 getElementById,以便在单击时显示为全尺寸。我可以在我的代码中直接使用 JavaScript 内联 onsubmit。内联 JavaScript 正在工作;缩略图正在显示,单击时显示全尺寸,但我想使用我的数据库检索到的图像在单击时显示全尺寸图像。你觉得你能帮我写代码吗?
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<script type="text/javascript">
//function that shows full sized image of the thumbnail
function showImage(imageID) {
//first hide all images
document.getElementById('image1').style.display = 'none';
//then display the one that had its thumbnail clicked.
document.getElementById(imageID).style.display = '';
}
</script>
</head>
<body>
<h1></h1>
<?php
$host = "localhost";
$user = "root";
$pass = "";
$database = "travel1";
$conn = new mysqli($host, $user, $pass, $database);
if ($conn->connect_error)
die ("Unable to connect to database: " . $conn->connect_error );
$sql = "select * from what_to_do
where DESTINATION='NEW YORK CITY'";
$result = $conn->query($sql);
if ($result->num_rows >= 0) {
echo "<table>";
while($row = $result->fetch_assoc()) {
echo "<td>".$row["THUMBNAIL"]."</td>";
}
echo "</table>";
}
else {
echo "You have no destinations";
}
$conn->close();
?>
<p>
<img id="image1" alt="" src="images/NewYork/Pick7/9-11show.jpg"
style="display: none" />
</p>
<p>
<img alt="" src="="images/NewYork/Pick7/9-11thumb.JPG"style="width:100px;
height:100px" onclick="showImage('image1')" />
</p>
【问题讨论】:
标签: javascript php html css