我正在创建一个网页,每个缩略图中都包含图像(一个缩略图中至少有3个图像)。我正在从数据库中检索这些图像。我的代码如下:
{foreach $rows as $row}
<img src="{$row.item_picture}"/>
{/foreach}
但是,我想把这些图像存储在一个列表中,这样,我就可以让图像在缩略图中连续移动,如下所示:
<html>
<head>
<link rel="stylesheet" type="text/css" href="C://Users//ts00333776//Desktop//theme.css">
<script type="text/javascript">
var rice= new Array() // create new array to preload images
rice[0] = new Image() // create new instance of image object
rice[0].src = "C://Users//ts00333776//Desktop//images//rice1.jpg" // set image src property to image path, preloading image in the process
rice[1] = new Image()
rice[1].src = "C://Users//ts00333776//Desktop//images//rice2.jpg"
rice[2] = new Image()
rice[2].src = "C://Users//ts00333776//Desktop//images//rice3.jpg"
</script>
</head>
<body>
<center>
<table>
<tr>
<td class="first">
<div class="second">
<div class="third">
<img src="C://Users//ts00333776//Desktop//images//rice1.jpg" id="slide" height="250px" width="250px"/>
</div>
<center><h4>some description</h4></center>
</div>
</td>
</tr>
</table>
</center>
<script type="text/javascript">
//variable that will increment through the images
var step=0
function slideit(){
//if browser does not support the image object, exit.
if (!document.images)
return
document.getElementById('slide').src = rice[step].src
if (step<2)
step++
else
step=0
//call function "slideit()" every 2.5 seconds
setTimeout("slideit()",2500)
}
slideit()
</script>
</body>
</html>`
但是,在上面的代码中,我从本地检索图像,而不是从数据库检索图像。有人能帮我把图像存储在从phpmyadmin检索到的列表中吗。这样我就可以在缩略图中移动图像。如何移动从数据库中获取的缩略图中的图像?我走的路对吗?感谢您的帮助。
JavaScript无法直接连接到MySQL数据库;您需要使用服务器端脚本语言来至少从数据库中检索结果。然后,您可以使用该语言直接在页面中显示结果,也可以将结果传递给JavaScript(例如,如果您正在执行自动完成文本字段,这会更有用,但如果您只是显示内联图像,则可能不那么有用)。
在这种情况下,最常用的语言可能是PHP,但您可以在Python、Perl、Ruby、Java等中使用。最大的决定因素可能是你的托管提供商为你提供了什么,其次是你更熟悉的语言。