如何从NivoSlider中的MySQL数据库加载图像。我似乎无法找到解决方案。我想创建一个jQuery图像滑块。我需要动态加载存储在我的MYSQL数据库中的图像。
任何建议都将不胜感激。
这是我的剧本:
</script></div>
<div class="jquery-script-clear"></div>
</div>
</div>
<h1 style="margin-top:150px;" align="center">jQuery Nivo Slider Demo</h1>
<div id="wrapper">
<div class="slider-wrapper theme-default">
<div id="slider" class="nivoSlider">
<?php
$connection = mysql_connect("localhost", "root", ""); // Establishing Connection with Server
$db = mysql_select_db("user"); // Selecting Database
$sql = mysql_query("SELECT * FROM images ORDER BY image DESC LIMIT 10") or die(mysql_error());
while($row = mysql_fetch_array($sql)){
$image = $row['image'];
$id = $row['id'];
$pic = "upload/$image";
if (file_exists($pic)) {
print '<img src=\"upload/$image\"/>';
$i++;
}
}
?>
</div>
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery.nivo.slider.js"></script>
<script type="text/javascript">
$(window).load(function() {
$('#slider').nivoSlider();
});
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-36251023-1']);
_gaq.push(['_setDomainName', 'jqueryscript.net']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
更新的代码:
<?php
$connection = mysql_connect("localhost", "root", ""); // Establishing Connection with Server
$db = mysql_select_db("user"); // Selecting Database
$sql = mysql_query("SELECT * FROM images ORDER BY image DESC LIMIT 10")or die(mysql_error());
while($row = mysql_fetch_array($sql)){
$image = $row['image'];
$id = $row['id'];
$pic = "upload/".$image";
if (file_exists($pic)) {
print '<img src=\"upload/$image\"/>';
$i++;
}
}
?>
答案 0 :(得分:0)
为此,您需要服务器端代码(如PHP,nodejs,asp.net)。
程序将是这样的
1)在服务器中创建端点,用于从数据库加载图像数据。 2)然后将数据写入客户端 load and show image from database using php
3)使用滑块中的图像。