我在我的项目中创建了一个jssor滑块,它运行得很好。我决定将数据库添加到我的项目中,我想将图像地址保存到数据库,所以我可以将图像添加到滑块。
1.我的问题是可以动态图像到滑块?
2.我想要的是从数据库我将得到所有图像,我将做一个foreach显示图像
这就是我做代码的方式
<div u="slides" style="cursor: move; position: absolute; left: 0px; top: 0px; width: 720px; height: 480px;
overflow: hidden;">
<?php
foreach (LoadImageGallery() as $value){
echo $value['searchresultbigimg'];
echo "<li><img src=\"admin/".$value['searchresultbigimg']."\"></li>";
echo $value['searchresultthumbnailimg'];
echo "<li><img src=\"admin/".$value['searchresultthumbnailimg']."\"></li>";
}
?>
</div>
UPDATE
当我尝试你的解决方案时我得到这个错误先生jssor这是我试过的
Slides html code definition error, there must be at least 1 slide to initialize a slider.
<div u="slides" style="cursor: move; position: absolute; left: 0px; top: 0px; width: 600px; height: 300px; overflow: hidden;">
<?php
foreach (LoadImageGallery() as $value){
echo $value['searchresultbigimg'];
echo "<div><img src=\"admin/".$value['searchresultbigimg']."\"></div>";
echo $value['searchresultthumbnailimg'];
echo "<div><img src=\"admin/".$value['searchresultthumbnailimg']."\"></div>";
}
?>
</div>
答案 0 :(得分:1)
是的,你可以和你在一起。
但你应该使用'DIV'而不是'LI'。
Jssor Slider幻灯片html代码如下,
<div><img u="image" src="image.jpg" /></div>
参考http://www.jssor.com/development/define-slides-html-code.html
答案 1 :(得分:0)
我想你想要这样的东西。我在这里找到了数组的基本代码http://www.the-art-of-web.com/php/directory-list-spl/
<?php
// filetypes to display
$imagetypes = array("image/jpeg", "image/jpg", "image/png");
function getImageList($dir)
{
global $imagetypes;
// array to hold return value
$imagefiles = array();
// add trailing slash if missing
if(substr($dir, -1) != "/") $dir = "images";
// open directory for reading
$d = new DirectoryIterator($dir) or die("getImageList: Failed opening directory $dir for reading");
foreach($d as $fileinfo) {
// skip hidden files
if($fileinfo->isDot()) continue;
$imagefiles[] = array(
'file' => "{$dir}{$fileinfo}"
);
}
shuffle($imagefiles);
return $imagefiles;
}
?>
<div id="slider1_container" style="position: relative; margin: 0 auto; top: 0px; left: 0px; width: 1000px; height: 800px;">
<div data-u="slides" style="cursor: move; position: absolute; left: 60px; top: 0px; width: 1000px; height: 800px; overflow: hidden;">
<?php
// fetch image details
$images = getImageList("images/");
// generate list for slideshow
foreach($images as $img) {
$path = ("{$img['file']}");
// display on page
echo <<<JSDIVS
<div>
<div><img data-u="image" src2="$path" style="position: relative; display: block; bottom:0;"/></div>
</div>
JSDIVS;
}
?>
</div>
</div>