我的数据库包含带有图片文件路径的记录。我想检索这些记录,并将它们放入php数组中,这样我就可以在网页上显示图片。图片将显示在页面的中心,并带有用于导航的左右按钮。
我希望实现的目标是,当按下左侧按钮时,它将显示上一条记录,当按下右侧按钮时,将显示下一条记录
有人告诉我,使用javascript和数组是最好的方法。因此,如果有人能告诉我如何做到这一点,将不胜感激
条目将按picture_id排序,包含路径的字段标记为file_location
数据库查询。表presentation
被赋予唯一的code
和id
,并且表slide
包含file_location
并且还具有其所属呈现的唯一id
和id
$sql_pres_slide= new CGenRs("SELECT * FROM presentation", $cao);
$sql_pres_slide->first();
$sql_pres_select= new CGenRs("SELECT * FROM slide where presentation_id='".$sql_pres_slide->valueof('pres_id')."'", $cao);
$sql_pres_select->first();
html
<table border="1" align="center">
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><span onclick="<?php echo "PREVIOUS DATABASE RECORD" ?>" style="color: #999; font-size: 25px" class="glyphicon glyphicon-menu-left" ></span></td>
<td> <div class="backgrund_img" >
<img src="../administration/file_manager/files/samsungS4-portrait-white.png" class="background_img" style="height:786px; width:406px; " />
<div id="inside_img"><img src="<?php echo $sql_pres_select->valueof('file_location') ?>" style="width: 360px; height:640px;"/></div>
</div>
</td>
<td><span onclick="<?php echo "NEXT DATABASE RECORD" ?>" style="color: #999; font-size: 25px" class="glyphicon glyphicon-menu-right" ></span></td>
</tr>
</table>
我不确定是否理解你的问题,但在我看来有点困惑。。。你想实现一个旋转木马(网络上有很多,随时可以使用),但总的来说,当用户按下左键或右键时,你谈论的是使用javascript获取图像。
在我看来,这可以使用两种不同的方法:1.将所有图像加载到javascript数组中2.在javascript var中加载第一个图像,并使用ajax调用返回或前进。
让我们看看的几个例子
第一种方法:
<script type="text/javascript">
var images=new Array(<?php implode($images);?>);
$().ready(function(){
$('prev').click(function(){
//go to previous image
})
$('next').click(function(){
//go to next image
})
})
</script>
第二种方法:
<script type="text/javascript">
var images=<?php $images[0];?>;
$().ready(function(){
$('prev').click(function(){
$.ajax({
url: "yourPhpImageScroller.php",
data: {direction:'prev'},
success: function(data){
//go to previous image
}
});
});
}):
$('next').click(function(){
$.ajax({
url: "yourPhpImageScroller.php",
data: {direction:'next'},
success: function(data){
//go to next image
}
});
});
})
})
</script>
我假设$images是一个php数组,包含您的所有图像